Welcome Guest | Sign in | Register
Inheritance - Discussion Page For Q.2825 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Inheritance > Questions and Answers

Q: What is the output for the below code ?

public class A {
public void printValue(){
public class B extends A{
public void printNameB(){
public class C extends A{
public void printNameC(){
1. public class Test{
2. public static void main (String[] args) {
3. B b = new B();
4. C c = new C();
5. newPrint(b);
6. newPrint(c);
7. }
8. public static void newPrint(A a){
9. a.printValue();
10. }
11. }
A. Value-A Name-B B. Value-A Value-A
C. Value-A Name-C D. Name-B Name-C

Answer and Explanation

Answer:Value-A Value-A

Class B extended Class A therefore all methods of Class A will be available to class B except private methods. Class C extended Class A therefore all methods of Class A will be available to class C except private methods.

Comment on this Question



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.