0
I made an abstract class and three subclasses of that class.When I override toString method, I want to return the values of variable of subclass(from toString method) and not the superclass.But it gives the value of superclass.What to do??
2 odpowiedzi
+ 1
it may be becouse you are using an instance of super-class not sub-class. 
Try the below
Ex:
abstract class Father {}
class Son extends Father {
   public String toString() {
      return "I am the Son class";
   }
}
public class Program
{
    public static void main(String[] args) {
        
    Father f = new Son ();
    System.out.println (f);
    }
}
0
ohkk thanxx👍👍





