package com.test;
public class Main {
public static void main(String[] args) {
System.out.println(new B().toString());
}
}
package com.test;
class A {
@Override
public String toString() {
// TODO Auto-generated method stub
return this.getClass().getName();
}
}
package com.test;
public class B extends A {
}
This program gives output com.test.B but if I change toString method of class A to
@Override
public String toString() {
return "hello";
}
Then it print hello. why?
Band now it's printinghellobut the method is inA. I would start with the basics of inheritance to understand.