public class StudentA extends marks \\child class
{
public double maths;
public double chemistry;
public double physics;
double percentage;
public StudentA(integer maths, integer chemistry, integer physics)
{
system.debug('maths marks are' + maths);
system.debug('chemistry marks are' + chemistry);
system.debug('physics marks are' + physics);
}
public double percentage()
{
percentage = (maths+chemistry+physics/3);
system.debug('percentage is' + percentage);
return percentage;
}
public override void getpercentage()
{
system.debug('total percent' + percentage);
}
}
object:
StudentA v = new StudentA(99,98,99);
v.percentage();
v.getpercentage();
注意:我正在尝试计算获得的标记的总百分比,当我执行它时给我错误“尝试取消引用空对象”。
在输出中只打印标记。在此处输入图像描述 错误屏幕截图并执行输出。
在此处输入图像描述mgur.com/tiJe2.png