Java Abstract Classes & interfaces

Source: Internet
Author: User
Tags modifier

1, is there a constructor in the abstract class? There, used to initialize the subclass object. 2, abstract keywords can not coexist with those keywords? private, no, static, no final. Final keyword: 1,final is a modifier that can be used to modify classes, methods, and variables. 2,final-Modified classes cannot be inherited. 3,final-Modified methods cannot be overridden. A variable modified by 4,final is a constant that can be assigned only once. Why use final modifier variables. In fact, in the program if a data is fixed, then the direct use of this data can be, but so poor reading, so it is the name of the data. And the value of this variable name cannot be changed, so add final fixed. For members that are common to interfaces: and these members have fixed modifiers. 1, global constant: public static final 2, abstract method. Public abstract This concludes that the members in the interface are common permissions. A class is an inheritance relationship with a class, and a class is a direct implementation relationship with an interface. /* interfaces cannot be instantiated. The subclass can be instantiated only by implementing the subclass of the interface and overriding all the abstract methods in the interface. Otherwise, this subclass is an abstract class. Multiple inheritance is not directly supported in Java because of the uncertainty of the call. So Java improved the multi-inheritance mechanism and became a multi-implementation in Java. A class can implement multiple interfaces. A class can also implement multiple interfaces while inheriting another class. The presence of interfaces avoids the limitations of single inheritance. the similarities and differences between abstract classes and interfaces:The same point: it is always drawn upward.   Different points: 1, abstract classes need to be inherited, and can only be inherited. Interfaces need to be implemented and can be implemented more.   2. Abstract methods and non-abstract methods can be defined in an abstract class, and after the subclass inherits, non-abstract methods can be used directly. Only abstract methods can be defined in an interface and must be implemented by subclasses. 3, the inheritance of abstract class, is a relationship, in the definition of the basic commonality of the system

Java Abstract Classes & interfaces

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.