Encapsulating inherited polymorphism

Source: Internet
Author: User

Java is an object-oriented language, Java object-oriented generally have three major characteristics: encapsulation, inheritance, polymorphism.

Encapsulation : It is the encapsulation of properties and methods into a class.

inheritance : As subclasses inherit some properties and methods of the parent class.

polymorphic: Just as a parent class has multiple subclasses of different characteristics.

Here I do not explain more, below I mainly explain an inheritance. Inheritance is a feature of OOP (object oriented), and Java only supports single inheritance (if you inherit two parent classes that have the same method, then you do not know the inheritance to that parent class, so Java only supports single inheritance). Inheritance is a feature of Java, so we use the class to inherit the Objict class, so we need the method of object class, such as ToString (), GetClass (), wait () ... So the classes we build have parent classes.

There are generally three kinds in Java:

Basic Class : That is, the general class (generally referred to as the class is the basic Class), is the object template, is a collection of properties and methods. You can inherit other basic classes, abstract classes, and implement interfaces.

abstract class : A class with an abstract method (the abstract method is that the method must be implemented by inheritance, itself defined, not implemented). Abstract classes can have one or more abstract methods, which are the excesses of basic classes and interface classes.

interface Classes : Generally called interfaces, all methods in the class are abstract methods, and the methods of the class themselves are defined not to be implemented.

Abstract class and interface A by the "abstract class + abstract class name" is defined by "interface + interface name", the interface of the method is an abstract method, and the abstract class has a part of the method is implemented by itself, some definitions are not implemented.

Encapsulating inherited polymorphism

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.