Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

JAVA Programming :: Inheritance

Home > JAVA Programming > Inheritance > Discussion

9. What is the output for the below code ?

1. public class A {
2. public void printName(){
3. System.out.println("Value-A");
4. }
5. }
6. public class B extends A{
7. public void printName(){
8. System.out.println("Name-B");
9. }
10. }
11. public class C extends A{
12. public void printName(){
13. System.out.println("Name-C");
14. }
15. }
16. public class Test{
18. public static void main (String[] args) {
19. B b = new B();
20. C c = new C();
21. b = c;
22. newPrint(b);
23. }
24. public static void newPrint(A {
25. printName();
26. }
27. }

Answer: Option C

Explanation :

Reference variable can refer to any object of the same type as the declared reference OR can refer to any subtype of the declared type. Reference variable "b" is type of class B
and reference variable "c" is a type of class So Compilation fails.

Post Your Answer Here:     

Name *
Email
Alert me

No Discussion on this question yet!