148k views
1 vote
Consider the following class definitions. public class BClass { private int x; public void set(int a) { x = a; } public void print(){ } } public class DClass extends BClass { private int y; public void set(int a, int b) { //Postcondition: x = a; y = b; } public void print(){ } } Which of the following is the correct definition of the method set of the class DClass? (i) public void set(int a, int b) { super.set(a); y = b; } (ii) public void set(int a, int b) { x = a; y = b; }

1 Answer

3 votes

Answer:

The answer to the given question is the option "(i)".

Explanation:

In this question, the correct option is the "(i)" because In this method definition we use the super keyword. It refers to the parent's class. In this method, we use the superclass to call the above (parent) class method. and if we choose the option (ii), It will not call the parent class. That's why we use the option (i) which is correct.

User Taeber
by
5.8k points