Java object-oriented-abstract classes and interfaces

Source: Internet
Author: User

First, Final keywords:

The 1.final keyword in Java is called the end device, which means the final meaning

2.final can declare classes, methods, properties:

Classes that use Final declaration cannot be inherited

Methods that use Final declaration cannot be overridden

Variables declared with fanal become constants, and constants cannot be modified. When a variable becomes a constant, uppercase is generally used, for example: final int age = 22;


Second, abstract class:

1. A class that contains an abstract method is an abstract class.

2. a method that is declared without being implemented is an abstract method. You must use the abstract declaration.

3. Abstract class quilt inheritance, it cannot be instantiated directly, it must be instantiated through its subclasses. If the subclass is not an abstract class, you must override all abstract methods in the abstract class.

4. Format:

Abstract class classname{attribute//1 method//2 Abstraction Method//3 1, 2, 3 is not required, but optional }


Third, the interface:

1. Interfaces can be understood as a special class, all of which are composed of global constants and common abstract methods .

Examples of global constants: public static final int. age = 100;

2. Format:

Interface interfacename{Global constant//1 abstract method//2 1, 2 is optional}

3. The implementation of the interface must also be through subclasses, using the keyword implements, and the interface can be implemented more

4. A subclass can inherit abstract classes and implement interfaces at the same time

5. An interface cannot inherit an abstract class, but it can inherit multiple interfaces at the same time through the Extens keyword, implementing multiple inheritance of the interface. Compensate for the lack of single inheritance in Java.





Java object-oriented-abstract classes and interfaces

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.