Directly on the code:
class father { private string aaa = "I'll Test"; . public father () { system.out.println (" Father this.getclass (): "+this.getclass ());//Represents the class of the object at the current runtime system.out.println ("Father this.hashcode (:" +this.hashcode ()); system.out.println ("Father this:" +this); System.out.println ("FATHER THIS.AAA:" +this.aaa); this.test (); } private void test () { system.out.println ("I am the method of privatization"); } public int dowork () { system.out.println ("I'm going to work"); return 1; }}class son extends father { private String bbb = "I'll test 1"; public son () { system.out.println ("Son super.getclass ():" + Super.getclass ());//Indicates the class system.out.println of the parent class runtime ("son This.hashcode (): "+this.hashcode ()); system.out.println (" Son this: "+this); }}public class fatherdemo{ public static void main (String[] args) { Father f = new son (); }}
The result of the operation is this:
Father This.getclass (): Class Xiaomage. Son
Father This.hashcode (: 581882789
Father This:[email Protected]
Father This.aaa: I'll test it.
I'm a privatization method.
Son Super.getclass (): Class Xiaomage. Son
Son This.hashcode (): 581882789
Son This:[email protected]
This article is from the "Puma Bar" blog, please be sure to keep this source http://sherwin28.blog.51cto.com/2904903/1812119
Does the Java call constructor create an object?