Java Abstract class, java Abstract

Source: Internet
Author: User

Java Abstract class, java Abstract

Not to mention, let's start with a code segment.

Public class Abstract {public static void main (String [] args) {cl2 c = new cl2 (); c. method () ;}} abstract class Abc {public abstract void method ();} class cl2 extends Abc {public void method () {System. out. println ("Specific Method ");}}

There can be no abstract methods in an abstract class.

For example

Abstract class Abc {public void method () {System. out. println ("the methods in the abstract class can be specific ");}}

This is an abstract class, but its method is specific. This is acceptable and no error is reported.

However, if

class Abc{    abstract public void method();        }

This error is reported because abstract methods must be abstract classes.

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

 

Class cl2 extends Abc {public void method () {System. out. println ("Specific class ");}}

In this case, the ABC class is inherited, And the cl2 class is a specific class. Whether the class is abstract or specific is to look at the abstract keyword.

If this keyword exists, it is an abstract class, but not a specific class. Therefore, the above Code shows the specific class.

Continue

abstract class Abc{    abstract public void method();        }class  cl2 extends Abc{    }

Here, an error will be reported. Since there is no abstract keyword in cl2, It is a specific class, and the methods in it must be specific, but he inherits

The ABC class has abstract methods, so an error is reported. Therefore, the specific mehod method must be included in the chlorine.

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

For example

abstract class Abc{    abstract public void method();        }abstract class  cl2 extends Abc{   
}

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

But he does not need to be specific, because he is an abstract class.

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

The above are some notes for abstract classes.

In general, an abstract class can have no abstract method, but an abstract method must be an abstract class. A specific class must have a specific method.

 

I'm a beginner at the freshman dog level. Thank you for understanding.

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.