Java interface and abstract class small notes

Source: Internet
Author: User

Java interface and abstract class small notes

@author Ixenos

Interface

1. The interface does not have a constructor because the interface is not instantiated
2. Anonymous objects if the constructor that uses the interface also simply represents a covariant anonymous object that implements the interface
3. The member variables in the interface are the public static final type by default. The initialization that must be displayed.
4. The method in the interface is the public abstract type by default. An implicit declaration.
5. The interface cannot implement another interface, but it can inherit multiple interfaces.
6. If a class implements an interface, then all the abstract methods inside the interface must be implemented


Abstract class

1. If in the parent class (here is your abstract class) The constructor that is written and parameterized is displayed in the subclass, you must write a constructor to invoke the child class inheritance.
The constructor of the parent class
Example:

1 Abstract classperson {//defines an abstract class that must be inherited2Person (inti) {3     }4 }5 6  Public classStudentextendsPerson {7 Student () {8     Super(inti)://the calling parent class constructor method must be displayed//Super Represents the parent class object9     }Ten}

2. If there are no arguments in the parent class constructor, in the subclass can not display the constructor of the write parent class, Java will automatically call the constructor without parameters
Example:

1 Abstract classperson {//defines an abstract class that must be inherited2Person () {//This constructor can also be non-writable, and Java will add a constructor without parameters by default3     }4 }5 6  Public classStudentextendsPerson {7     //constructor Function8 Student () {9     //super ();//can not write, Java will call this super () method itselfTen     } One}

Java interface and abstract class small notes

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.