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();
Note: I am trying to calculate total percentage of marks obtained, when i executed it give me error "attempt to de-reference null object".
In output only marks are printed. enter image description here error screen shot is attached and output is also executed.
enter image description heremgur.com/tiJe2.png
You are not assigning the parameter values to the class variables
Please modify your code as follows: