Q. What will be the output?
class A{
int i = 10;
public void printValue(){
System.out.print("Value-A");
}
}

class B extends A{
int i = 12;
public void printValue(){
System.out.print("Value-B");
}
}

public class Test{
public static void main(String args[]){
A a = new B();
a.printValue();
System.out.print(a.i);
}
}

  • (A) Value-B 11
  • (B) Value-B 10
  • (C) Value-A 10
  • (D) Value-A 10 D. Value-A 11
πŸ’¬ Discuss
βœ… Correct Answer: (B) Value-B 10
Explanation: If you create object of subclass with reference of super class like ( A a = new B();) then subclass method and super class variable will be executed.
Explanation by: Admin
If you create object of subclass with reference of super class like ( A a = new B();) then subclass method and super class variable will be executed.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
120
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Admin
Publisher
πŸ“ˆ
92%
Success Rate