Which two options, when inserted independently inside class Base, ensure that the class is being properly encapsulated and allow the program to execute and print the square of the number?

Given:
class Base {
// insert code here
}
public class Derived extends Base{
public static void main(String[] args) {
Derived obj = new Derived();
obj.setNum(3);
System.out.println("Square = " + obj.getNum() * obj.getNum());
}
}
Which two options, when inserted independently inside class Base, ensure that the class is being properly encapsulated and allow the program to execute and print the square of the number?
A. private int num;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
B. public int num;
protected public int getNum() {
return num;
}
protected public void setNum(int num) {
this.num = num;
}
C. private int num;
public int getNum() {
return num;
}
private void setNum(int num) {
this.num = num;
}
D. protected int num;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
E. protected int num;
private int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}

Download Printable PDF. VALID exam to help you PASS.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.