Which two options, when inserted independently inside class Base…?

Given: 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: 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.
protected int num;private int getNum() {return num;}public void setNum(int num)
{this.num = num;}

B.
protected int num;public int getNum() {return num;}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.
private int num;public int getNum() {return num;}public void setNum(int num) {this.num =
num;}

E.
public int num;protected public int getNum() {return num;}protected public void
setNum(int num) {this.num = num;}

Explanation:



Leave a Reply 2

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


renko

renko

Two Correct lines:
– private int num;public int getNum() {return num;}public void setNum(int num) {this.num = num;}
– protected int num; public int getNum() {return num;} public void setNum(int num) {this.num = num;}

Code:
public class Derrived extends Base{

public static void main(String[] args) {
Derrived obj = new Derrived();
obj.setNum(3);
System.out.println(“Square = ” + obj.getNum() * obj.getNum());
}

}
public class Base {
// insert code here
=>OK private int num;public int getNum() {return num;}public void setNum(int num) {this.num = num;}
//public int num; protected public int getNum() {return num;}protected public void setNum(int num) {this.num = num;}
//private int num;public int getNum() {return num;}private void setNum(int num) {this.num = num;}
=>OK protected int num; public int getNum() {return num;} public void setNum(int num) {this.num = num;}
//protected int num; private int getNum() {return num;} public void setNum(int num) {this.num = num;}
}