Java & Abstract Classes

Source: Internet
Author: User

/* Abstract class: Abstract: General, vague, can not understand! Not specific. Features: 1, the method is an abstract method, and it needs to be modified only when the declaration is not implemented. Abstract methods must be defined in an abstract class. The class must also be modified by the abstract. 2, abstract classes cannot be instantiated. Why? Because it doesn't make sense to invoke an abstract method. 3, an abstract class must have its subclasses overwrite all of the abstract methods before the subclass can be instantiated. Otherwise, this subclass is an abstract class. 1, is there a constructor in the abstract class? There, used to initialize the subclass object. 2, can abstract classes not define abstract methods? OK. However, it is rare to have the class create an object. The adapter object for AWT is this class. Usually the method in this class has a method body, but there is no content. Abstract class Demo{void Show1 () {} void Show2 () {}} 3, keyword cannot coexist with those keywords? Private not static no final No 4, abstract class and general class similarities and differences. The same point: abstract classes and general classes are used to describe things, and members are internally determined.   Different: 1, the General class has enough information to describe things. Abstract classes may not have enough information to describe things.   2, abstract methods cannot be defined in general classes, only non-abstract methods can be determined. Abstract methods can be defined in abstract classes, and non-abstract methods can also be defined.   3, the generic class can be instantiated. Abstract classes cannot be instantiated. 5, the abstract class must be a parent class? Yes. You can instantiate a child class only if it needs to overwrite its method.
*/Abstract classdemo{Abstract /*Abstract*/ voidShow (); }/*class Demoa extends demo{void Show () {System.out.println ("Demoa show");    }}class demob extends demo{void Show () {System.out.println ("demob show"); }}*/Abstract classCanine Branch {Abstract voidroar ();}classDogextendsCanine Branch {voidRoar () {System.out.println (Barking); }}classWolfextendsCanine Branch {voidRoar () {System.out.println (Whining); }}classAbstractdemo { Public Static voidMain (string[] args) {System.out.println ("Hello world!"); }}

Java & Abstract Classes

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.