Does the Java call constructor create an object?

Source: Internet
Author: User

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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.