public class Testdog {
publicstatic void Main (string[] args) {
Dog d = Newdog ();
D.setage (10);
D.setname ("Floral");
D.sethostname ("Xiao Ming");
System.out.println ("Name:" + d.getname () + "Age:" +d.getage ()
+ "HostName:" + d.gethostname ());
System.out.println (D.tostring ());
}
}
Biological
Class Creator {
Private intage;
Public Intgetage () {
Returnage;
}
Public Voidsetage (int.) {
This.age =age;
}
Publiccreator () {
Super ();
System.out.println ("This is Creator ' s constructor");
}
}
Animal class
Class Animal extends Creator {
Privatestring name;
Publicstring GetName () {
Returnname;
}
Public Voidsetname (String name) {
THIS.name =name;
}
Publicanimal () {
Super ();
System.out.println ("This is Animal ' s constructor");
}
}
Dog
Class Dog extends Animal {
Privatestring HostName;
Publicstring GetHostName () {
Returnhostname;
}
Public Voidsethostname (String hostName) {
This.hostname = HostName;
}
Public Dog () {
Super ();
System.out.println ("This is the Dog ' s constructor");
}
}
Java Learning--the whole process of subclass object instantiation