Class C extends B and B extends A and how can I directly access a method of A from class C without creating an instance of A.
Options:
1. super.test()
2. super.super.test()
3. There is no way we can access the class A method without creating an instance from class C.
Answer is 3
Here is the example code (they are not given this code, I only wrote for understanding clearly)
1. class A{
public A(){
System.out.println("A");
}
public void test(){
System.out.println("test method of A");
}
}
class B extends A{
public B(){
System.out.println("B");
}
public void test(){
System.out.println("test method of B");
}
}
class C extends B{
public C(){
System.out.println("C");
}
public void test(){
System.out.println("test method of C");
}
}
public class SuperKeyWord{
public static void main(String args[]){
C c = new C();
}
}
Question 2:
Write an immutable java class example.
Question 3:
Write a java program to reverse a given string.
Question 4:
Choose all right answers from the below options.
a. public synchronized(this) void test(){}
b. public void test(){ synchronized(Test.class){}}
c. public void test(){ synchronized(a) {}}
d. public synchronized void test {}
e. public void test{ synchronized(this) {}}
Options:
1. super.test()
2. super.super.test()
3. There is no way we can access the class A method without creating an instance from class C.
Answer is 3
Here is the example code (they are not given this code, I only wrote for understanding clearly)
1. class A{
public A(){
System.out.println("A");
}
public void test(){
System.out.println("test method of A");
}
}
class B extends A{
public B(){
System.out.println("B");
}
public void test(){
System.out.println("test method of B");
}
}
class C extends B{
public C(){
System.out.println("C");
}
public void test(){
System.out.println("test method of C");
}
}
public class SuperKeyWord{
public static void main(String args[]){
C c = new C();
}
}
Question 2:
Write an immutable java class example.
Question 3:
Write a java program to reverse a given string.
Question 4:
Choose all right answers from the below options.
a. public synchronized(this) void test(){}
b. public void test(){ synchronized(Test.class){}}
c. public void test(){ synchronized(a) {}}
d. public synchronized void test {}
e. public void test{ synchronized(this) {}}
No comments:
Post a Comment