Welcome Guest | Sign in | Register
Inheritance - Discussion Page For Q.2835 | 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 {
private void printName(){
public class B extends A{
public void printName(){
public class Test{
public static void main (String[] args) {
B b = new B();
A. Value-A B. Name-B
C. Value-A Name-B D. Compilation fails - private methods can't be override

Answer and Explanation


You can not override private method , private method is not availabe in subclass . In this case printName() method a class A is not overriding by printName() method of class B. printName() method of class B different method. So you can call printName() method of class B.

Comment on this Question



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