In this example we retrieve, a value using toString() method of the object class. If you anyalyze the code shown below, you would find that  super(argument1, argument2) sends the input for a constructor in the Parent class, that in turn initializes two string variable and toString() returns the request to the client class as shown in lines 8 and 9.
  • The other useful methods of the Object class those are inherited by all classes.
    • clone(), equals(), finalize()

//javac Object_toString.java
public class Object_toString {
//enum Days{Monday, Tuesday};
public static void main(String[] args) {
// TODO Auto-generated method stub
Achild child1 = new Achild();
Bchild child2 = new Bchild();
System.out.println(child1.toString());
System.out.println(child2.toString());
}
}

// a parent class with a constructor
class Aparent
{
String fname, lname, caller;
public Aparent()
{
System.out.println("AParent default blank constructor ");
}
public Aparent(String fname, String lname)
{
System.out.println("AParent two string constructor " +fname +"\t"+ lname);
this.lname = lname;
this.fname= fname;
}
public String toString()
{
return("Hi there\t" + fname + "\t"+lname);
}
}

// an extended child class with a constructor
class Achild extends Aparent
{
public Achild()
{
System.out.println("\tAChild Constructor");
}
}
class Bchild extends Aparent
{
public Bchild()
{
super("Smith","Handy");
System.out.println("\tBChild Constructor");
}

}