Features of constructors in Java child parent classes-subclass instantiation Process __linux

Source: Internet
Author: User

Only as Learning notes


/* The constructors in a child parent class are initialized to a subclass object The constructor of the parent class also runs because the constructor of the subclass has an implicit statement super () Super (): a constructor that accesses the null parameter of the parent class.
Also, all constructors in subclasses have the default first row of super () for what subclasses must access constructors in the parent class. Because the data subclasses in the parent class can be directly fetched, so when the subclass object is established =, you need to see how the parent class initializes the data, so the subclass initializes the object by first accessing the constructor of the parent class if you want to access the constructor specified in the parent class.
You can specify the note by manually defining the Super statement: The Super statement must be an example of the first line of subclasses of a subclass constructor conclusion: All constructors of subclasses, default access constructors for null arguments of the parent class
Because the first line in each constructor function of a subclass has an implicit super. When there are no constructor functions for null arguments in the parent class, the subclass must manually access the constructor specified in the parent class through the Super statement form Of course: The first line of constructors in a subclass can also manually specify the this statement to access the constructor subclass in this class at least one constructor will access the constructor in the parent class/class Father//extends Object/This is the parent class of all classes {privat
	e String word;
	Father () {System.out.println ("Father 1");
		} father (String word) {This.word = Word;
	System.out.println ("Father 2" + word);
	Class Sun extends Father {Sun () {super ();//Not write will also be implicitly called SYSTEM.OUT.PRINTLN ("Sun 1");
		Sun (String word) {super (word);
	System.out.println ("Sun 2" + word);
		} class Extenddemo {public static void main (string []args) {string w = ' run ... ';
		Sun s = new Sun (); SYSTEM.OUT.PRINTLN ("---------------");
		
		
	Sun SS = New Sun (w); 
 }
}


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.