asked 202k views
2 votes
Consider the following class definitions. public class BClass { private int x; public void set(int a) { x = a; } public void print() { System.out.print(x); } } 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 correctly redefines the method print of DClass?

(i) public void print() { System.out.print(x + " " + y); }
(ii) public void print() { super.print(); System.out.print(" " + y); }

asked
User Emanresu
by
8.0k points

1 Answer

2 votes

Answer:

Option (ii) is the correct option to the following code.

Step-by-step explanation:

In the following code of the Java Programming Language, there is two print function after the set function then, we firstly set the value of x and print it through print function which is already declared then, we set the value of y through set function then, print the value of y through print function. So, that's why the following option is correct.

answered
User Kevin Driedger
by
7.8k points