Javase Review Diary: abstract class

Source: Internet
Author: User

/* * Abstract class * Abstract: * Object-oriented three core ideas; * Package: Package, PPP is part of package * inheritance; * Polymorphic: The reference of the parent class to the object of the subclass * Reference: Refers to a reference variable * What are the variables? * Member variables; * Local variables of the construction method; * Local variables of the common method; * Immediately declare the variables to be used immediately; * Static variables; * What is abstract class? * The class that is decorated with the abstract keyword is called an abstract class; * What is an abstract method? * Methods without method body are called abstract methods, not even {}; Abstract methods must be added to the modifier list with the keyword modifier; * Classes that inherit from the abstract class: * Must all implement the method in the abstract class (that is, with the method body brace), if not all implemented, it must be added to the abstract decoration, that is, he is also an abstraction class; * The relationship between abstract classes and abstract methods: * Classes containing abstract methods must be abstract classes; * Abstract classes do not necessarily have abstract methods; * Abstract classes do not have the purpose of abstract methods: * In order to make this abstract class cannot be instantiated; * Nature of abstract methods: * 1 Abstract methods cannot be instantiated (there is also a way to instantiate the class, that is, the construction method Privatization, private) * 2 Although the abstract method can not be instantiated, but there is still a construction method, which is to let the subclass create objects with (construction method cannot be inherited, with super ()) * 3 abstract class is not necessarily an abstract method, but the abstract method must be written in the abstract class * 4 abstract class Inheritance class, must be all the abstract method implementation (all need to add method body), otherwise the subclass is an abstract class, need to use The abstract modifier, or subclass, cannot be instantiated directly. * Note: The abstraction class cannot be modified with the final decoration, because the abstract classThe purpose of this is to inherit, and the final modified class cannot be inherited * can abstract methods be modified with final? * Abstract and final cannot be present at the same time, the abstraction method cannot be finished with the final modification, because the abstract method is intended to be overwritten, and the final modified method cannot be overwritten; * Also, subclasses must implement all the "abstract" methods of an abstract class, rather than using an abstract method? * about this, the code can be seen;  **/ Public classjavase{ Public Static voidMain (string[] args) {A a=NewC ();//here is polymorphic, for parent class references to child class objectsA.move ();        A.eat (); //Write One more//a o = new A ();//here is the error, I have written that the abstract class can not be instantiated, a is an abstract class bar, of course, can not be instantiated;    }}Abstract classa{//Abstract class Bar     Public voidEat () {//This is not an abstract method, it needs to be overwritten (implemented) it ?System. out. println ("This is an abstract class" ); }     Public Abstract voidMove ();//Note: There is no method body for the abstract method;A () {System. out. println ("the construction method of a" ); }}Abstract classB extends a{//B does not overwrite (or implement) the move () method in a, so he is still an abstract class, need to add abstract;B () {System. out. println ("construction method of B" ); }}classC extends b{//C implements all the methods in a, so do not use abstract modification;C () {super (); }     Public voidMove () {//The Move () method in a is used to overwrite theSystem. out. println ("C is not an abstract class" ); }}

Javase Review Diary: 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.