2.24 Java Basics Summary ①for-each loop ② Inheritance concept ③ Full class name ④ method rewrite

Source: Internet
Author: User

①for-each Loop ② Inheritance concept ③ Full class name ④ method rewrite

First, For-each cycle
When iterating through each element in the collection, one of the for loops
int [] A = {n/a};
for (int result:a) {
SYSTEM.OUT.PRINTLN (result);
}

All in turn, but no details are processed

Ii. inheritance
The relationship of Is-a
Subclass inherits all the properties and methods from the parent class, and the inherited access modifier limits
But constructs cannot be inherited, and the construction of the parent class will work in the construction
Pros: ① multiplexing ② Extended parent class properties and methods

Java is a single inheritance, a class has only one parent class
Single inheritance: The hierarchy structure is clear, the richness is not high, so Java in the interface to make up for more
Multiple inheritance: C + +, such as high richness, may appear a complex network and other inheritance relationships, the structure may not be clear

Third, class full name, class qualified name
①import Com.lovo.Son;
Son a = new Son ();

②com.lovo.son a = new Com.lovo.Son ();

Iv. Method Rewriting
Subclasses re-implementing methods of the parent class
① method Name, parameter list, return type all consistent
The access modifier for the ② subclass cannot be smaller than the parent class
Public > Private

2.24 Java Basics Summary ①for-each loop ② Inheritance concept ③ Full class name ④ method rewrite

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.