Summary of abstract classes and interfaces

Source: Internet
Author: User

class form of expression

Java code 650) this.width=650; "class=" star "src=" Http://yangnier.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>

    1. Public class a{}


characteristics of the class:
1) A property in a class can be a member property, or it can be a class property
2) A method in a class must be a method that has a method body, can be a member method, or it can be a class method
3) Each class must have at least one constructor method, the default is a parameterless construction method, you can call the constructor method to create the object
A class can inherit only one parent class, one root inheritance

Java code download Span style= "color: #000000;" >    650) this.width=650; "class=" star "src=" Http://yangnier.iteye.com/images/icon_star.png "alt=" collection Code "style=" border:0px; "/

    1. Public class a{}

    2. Public class B extends a{}

  
Abstract class 
form of expression:

Java code 650) this.width=650; "class=" star "src=" Http://yangnier.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>

    1. Public Abstract class a{}


features of abstract classes:
1) Properties in an abstract class, like classes, can be member properties or class properties
2) methods in an abstract class can be abstract methods or specific member methods
3) methods in an abstract class need to define access qualifiers
4) Abstract class has a constructor method, the default is a parameterless construction method, but cannot be used to create an object (that is, cannot new object)
5) Abstract class is used to act as the parent class, to inherit and extend the subclass.
  
A class can inherit only one abstract class
Download
interface (interface) 
form of expression:

Java code 650) this.width=650; "class=" star "src=" Http://yangnier.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>

    1. Public Interface a{}


features of the interface:
1) The attribute in the interface must be a public constant (the initial value must be assigned)
2) The properties in the interface default to public static final, which must be public static final
3) The methods in the interface must all be abstract methods only
4) The method in the interface is public abstract by default and must be public abstract
5) The access qualifier of the method in the interface defaults to public, which must be public
6) The interface has no construction method and cannot create an object (that is, it cannot be a new object)
7) The interface is used to act as a parent class to extend to subclasses.

There is also an implementation of the interface:
Download

Java code 650) this.width=650; "class=" star "src=" Http://yangnier.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>

    1. Public class A implements b{}


A class can implement multiple interfaces

Java code 650) this.width=650; "class=" star "src=" Http://yangnier.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>

  1. Public interface c{}

  2. Public interface d{}

  3. Public class E implements c,d{}

  
Note: The class implements the interface and must implement all the abstract methods in the [Override] interface
cannot reduce the visible range of a method when overriding inherited methods/implementing methods in an interface
      
A class can inherit a class first, and then implement multiple interfaces

Java code 650) this.width=650; "class=" star "src=" Http://yangnier.iteye.com/images/icon_star.png "alt=" Favorite Code "style=" border:0px; "/>

    1. Public class F extends A implements c,d{}


Summary of 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.