Java abstract class

Source: Internet
Author: User

Not much to say, the first paragraph of code.

 Public classabstract{ Public Static voidMain (string[] args) {Cl2 c=NewCl2 ();    C.method (); }}Abstract classabc{ Public Abstract voidmethod (); }classCl2extendsabc{ Public voidmethod () {System.out.println ("Concrete Method"); }}

There can be no abstract method in an abstract class.

Like what

Abstract class abc{    publicvoid  method ()    {        System.out.println (" The method of the abstract class surface can be specific ");}    }

This is an abstract class, but his method is specific, it is possible, no error.

But if

class abc{    abstractpublicvoid  method ();        

This is an error, because an abstract method must be an abstract class.

----------------------------------------

class  extends abc{    publicvoid  method ()    {                System.out.println ("specific class") );            }}

At this point the ABC class is inherited, and the Cl2 class is a concrete class. Are we in the region a class is abstract or specific, that is, to see the abstract keyword

If there is this keyword, he is an abstract class, not a specific class, so the above code in Cl2 is a concrete class.

Go on

Abstract class abc{    abstractpublicvoid  method ();         class  extends abc{    }

Here will be an error, Cl2 no keyword abstract so he is a concrete class, inside the method must be specific, but he inherited the

ABC class, has an abstract method, so will error, so need to Cl2 inside the specific Mehod method.

Of course, the subclass of the abstract class can also be an abstract class

Like what

Abstract class abc{    abstractpublicvoid  method ();         Abstract class  extends abc{   

Cl2 is an abstract class that inherits the ABC class and has an abstract method in the ABC class.

But he doesn't need to be specific, because he's an abstract class himself.

------------------------------------

Above are some points of attention in abstract class.

In general, an abstract class can have no abstract method, but abstract methods must be abstract classes, and concrete classes must be concrete methods.

Freshman dog Beginner, no, please understand

Java abstract class

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.