Java Abstract class "instantiation", java Abstract

Source: Internet
Author: User

Java Abstract class "instantiation", java Abstract

Without doubt, abstract classes cannot be instantiated. abstract classes do not describe a specific thing as a specific class. They extract the abstract of common features of similar specific things, and it has no meaning to implement them.

If the abstract class is not inherited but is "instantiated", the statement is as follows:

1 package subClass; 2 abstract class ParentClass {3 public abstract void abstractFun (); 4} 5 6 class SubClass {7 // here "instantiate" ParentClass is instantiated ParentClass (){}, and implements the abstract method of ParentClass. Therefore, the abstract class cannot be instantiated. 8 ParentClass parentClass = new ParentClass () {9 @ Override10 public void implements actfun () {11 System. out. println ("abstractFun ()"); 12} 13}; 14 15} 16 17 public class TestExtends {18 public static void main (String args []) {19 SubClass sub = new SubClass (); 20 sub. parentClass. abstractFun (); 21} 22}

Instantiate "ParentClass is new ParentClass () {}, and implements the abstract method of ParentClass, instead of newParentClass ().

The above structure is similar to Android event listening:

FindViewById (R. id. stop_Button). setOnClickListener (new View. OnClickListener (){
@ Override do not think it is an internal class when @ Override is omitted here.
Public void onClick (View v ){
StopService (it );
}
});

Abstract class features:
The abstract class must be inherited from non-abstract classes;

Related Article

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.