I am new to Java and was learning inheritance concept.The question is very simple. If one of my class inherits a method from other how can I display that it was inherited by classX?
public class class1 extends ClassPname {
public static void main (String[] args){
className obj3=new className();
class1 obj2=new class1();
obj3.Name();
obj2.Name();
}
}
This is the ClassPname code:
public class ClassPname {
public void Name(){
System.out.println("I am players name ;Succesfully inherited by ");
}
}
The final output is:
I am players name ;Succesfully inherited by
I am players name ;Succesfully inherited by
My desired output :
I am players name ;Succesfully inherited by(class that inherits this)
I am players name ;Succesfully inherited by (Class that inherits this)