Java language basics: abstract classes and interfaces

Source: Internet
Author: User

1. methods In a class are called abstract methods if only declarations are not implemented. abstract methods must be used for modification. abstract classes with abstract methods are called abstract classes. abstract methods must also be used for modification, abstract classes can have no abstract methods. abstract classes cannot be created:

View plaincopy to clipboardprint?
// Abstract class
Abstract class {
// Abstract Method
Abstract public void proc ();
}

// Abstract classes without abstract methods
Abstract class B {
Public void proc (){
}
}

Public class Main {
Public static void main (String [] args ){
// The abstract class cannot be created. The following two statements are incorrect.
A a = new ();
B B = new B ();
}
}
// Abstract class
Abstract class {
// Abstract Method
Abstract public void proc ();
}
 
// Abstract classes without abstract methods
Abstract class B {
Public void proc (){
}
}
 
Public class Main {
Public static void main (String [] args ){
// The abstract class cannot be created. The following two statements are incorrect.
A a = new ();
B B = new B ();
}
}
 

2. A subclass inherited from an abstract class. If it does not cover all methods of the abstract base class, it is also an abstract class and must be modified using abstract:

View plaincopy to clipboardprint?
// Abstract class
Abstract class {
// Abstract Method
Abstract public void proc ();
}

Abstract class B extends {
}
// Abstract class
Abstract class {
// Abstract Method
Abstract public void proc ();
}
 
Abstract class B extends {
}

3. All methods in the interface are abstract methods. They can only have public or default modifiers, and cannot have private or protected modifiers.

4. The interface can contain fields. These fields are implicitly declared as static final, that is, the fields in the interface can be considered as constants.

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.