Java Object Oriented OOP

Source: Internet
Author: User

1. Inheritance

(1) Constructors

Before calling the subclass constructor, the parent class constructor is called first, when the parent class constructor is not invoked by using "super (parameter or parameterless)" in the subclass constructor, and is the default call to the parent class's parameterless constructor, and if the parent class contains a parameter constructor, but there is no parameterless constructor, it must be used in the subclass constructor. Super (parameter) "specifies that the parameter constructor of the parent class is called, otherwise it will be an error."

2. Abstract class

(1) Abstract methods in a class must be declared as abstract classes.

(2) I built an interface, and then an abstract class implements this interface, and override all methods. Then I build a class extends this abstract class, and cannot provide any detail or method body for any abstract method, then this class must be an abstract class.

(3) When I build an interface, and then a class implements this interface, and cannot provide any detail or method body for any abstract method, this class must be an abstract class and override all methods. Then I build a normal class extends this abstract class, and I can do whatever I like. This is the case with the adapter pattern in Java design mode.

A, the final modified class is the end state class, cannot be inherited, and the abstract class must be inherited to have its meaning, therefore, final cannot be used to modify the abstract class. B, Final modified method is the final state method, cannot be rewritten. Instead of inheriting an abstract class, you must override its methods. C, abstract methods are declarations only, do not do the method of implementation.

1, abstract class can not be instantiated, the work of the instantiation should be left to its subclasses to complete, it only need to have a reference.

2. Abstract methods must be overridden by subclasses.

3. Whenever a class that contains an abstract method, the class must be defined as an abstract class, whether or not there are other methods included.

4, the abstract class can contain specific methods, of course, can not contain abstract methods.

5. Abstract cannot be modified in the same class as final.

6. Abstract cannot be modified with private, static, final, or native the same method. 、

Java Object Oriented OOP

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.