Question
class A { protected int a; private int c = 2; public int d; public void doThis(){ System.out.print(c + ); } protected int get C(){
class A { protected int a;
private int c = 2;
public int d;
public void doThis(){ System.out.print(c + );
} protected int get C(){ return c;
} }
class B extends A { private int b;
public void doThis(){
super.doThis(); // line 1
b = 1;
System.out.println(b + );
} } public class Tester { public static void main(String[] args) { A obj = new B(); // line 2
obj.doThis(); // line 3
} }
Which of the following is true with respect to A, B and Tester?
A is a superclass of B and Tester is not a subclass of A
Tester and B are both subclasses of A
B is a subclass of A but A is not a superclass of B
B is a subclass of A and A is a subclass of Tester
N.A.
Which of the following data are accessible in class B?
a, b, d
a, b, c, d
b
a, b
N.A.
The statement marked by comment // line 1 does which of the following?
calls the constructor as defined in the current class
calls the constructor as defined in the parent of the current class
calls the method doThis() defined in class A
N.A.
calls the method doThis() defined in class B
What is true about the line commented as //line 2, in class Tester?
line 2 will compile and during execution the variable obj will refer to an object of type A
N.A.
line 2 will not compile because type of variable obj does not match the type of object
line 2 will compile and during execution the variable obj will refer to an object of type B
line 2 will compile but will throw an exception during execution
What is the output of running line commented as //line 3 in class Tester;
line 3 will not compile
2 1
2
N.A.
1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started