java--super keyword, final keyword, abstract class, interface

Source: Internet
Author: User

Super Keyword:

When the parent class is overridden, the subclass object cannot access the overridden method of the parent class, and super is to solve the problem:

1. Use the Super keyword to access the member variables and member methods of the parent class:

Super. Member variables

Super. Member method ([Parameter 1, ...])

2. Use the Super keyword to access the constructor of the parent class: (try to define an argument-free constructor in the class to avoid an error in inheritance).

Final keyword:

The 1.final keyword-decorated class cannot be inherited.

The 2.final keyword decoration method cannot be overridden.

The final modified variable in 3.java is called a constant, and once assigned, its value cannot be changed.

Abstract class:

Abstract methods: Methods that do not contain method bodies are abstract methods, and abstract methods must be decorated with the abstract keyword:

abstract void shout ();

Abstract class: When an abstract method is included in a class, the class must be decorated using the abstract keyword. Abstract classes may not contain abstract methods, but classes with abstract methods must be abstract classes. Abstract classes cannot be instantiated.

Interface:

1. If all the methods of an abstract class are abstract, you can define the class in a different way, that is, the interface.

2. An interface is a special class consisting of constants and abstract methods, which is a further abstraction of an abstract class, and the purpose of the interface is to implement multiple inheritance.

3. Use interface to declare.

4. The class to inherit the interface needs to use the Implements keyword, it is important to note that a class implementation of an interface, must give the interface of all the methods of implementation, if a method cannot be implemented, you must write an empty method.

5. Inheritance between interfaces with extends

6. A class can implement an interface while inheriting another class, at which point the extends keyword must precede the Implements keyword.

Upward transformation:

Use child class objects as parent classes

Downward transformation:

Use the parent class object as a subclass

java--super keyword, final keyword, abstract class, interface

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.