Big Data Java Inheritance on

Source: Internet
Author: User

Overview of Inheritance

When the same properties and behaviors exist in multiple classes, the content is extracted into a single class, so that multiple classes do not need to define these properties and behaviors, as long as the class is followed.

Multiple classes can be called subclasses, and this class alone is called a parent class or a superclass.

Subclasses can access non-private properties and behaviors directly in the parent class.

An inheritance relationship between classes and classes is made through the extends keyword.

Class Subdemo extends demo{}

The advent of inheritance increases the reusability of the code.

The emergence of inheritance gives a relationship between classes and classes, providing a precondition for polymorphism.

Characteristics of inheritance

Java only supports single inheritance and does not support multiple inheritance.

A class can have only one parent class, and there can be no more than one parent class.

Class Subdemo extends demo{}//ok

Class Subdemo extends Demo1,demo2...//error

Java supports multilayer inheritance ( inheritance system )

Class a{}

Class B extends a{}

Class C extends b{}

Defining inheritance requires attention:

Do not inherit just to get a feature in another class

between classes and classes to have a owning ("is a") relationship,xx1 is a kind of xx2.

Super Key Words

the use of Super and this is similar

This represents a reference to this class of objects

Super represents the identity of the memory space of the parent class.

You can use Super to differentiate when the child parent has a member of the same name

subclasses you can use the Super statement when you want to call the parent class constructor .

Instantiation process of subclasses

All constructors in a subclass access the constructor of the parent hollow parameter by default

because the first row of each constructor has a default statement super ();

Final Key Words

Final can be decorated with classes, methods, and variables.

The final decorated class cannot be inherited.

the final modified method cannot be overridden.

The final modified variable is a constant. Can only be assigned once.

An inner class can only access a final decorated local variable.

Subclasses will have the data in the parent class, so it is first to be clear how the parent class initializes the data.

When the constructor of a parent class does not have an empty argument, the constructor of the subclass must Specify the constructor to be accessed through this or the super statement.

recently 51cto+it 18 Palm free Big Data course, interested small partners can go to Xu Peicheng teacher Live guest or video specific study.


This article is from the "11732319" blog, please be sure to keep this source http://11742319.blog.51cto.com/11732319/1790595

Big Data Java Inheritance on

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.