public class BClass private int x public void setint a xa
public class BClass
{
private int x;
public void set(int a)
{
x=a;
}
public void print()
{
Systme.out.print(x);
}
}
public class DClass extents BClass
{
private int y;
public void set(int a,int b)
{
//postcondition; x=a; y=b;
}
public void print()
{...}
}
1.write the definition of the print method of DClass that overrides it.
2.Write the definition of the method set of the class DClass.
Solution
1.Print method of DClass that overrides it is given below,
The java program waits till the runtime of the program and checks which object the reference is pointing to. In this case the object is of class D. So, it’s class D\'s print() method which is getting executed
2. The method set in the DClass is defined as ,
public void set(int a, intb)
{
super.set(a);
y=b;
}
The method contains the statement super.set(a); to call the method set with one parameter .

