About the final keyword and abstract class, interface

Source: Internet
Author: User

Final is primarily used to modify classes, methods, and properties

When used to decorate a class, the class cannot inherit from the quilt class, in other words, the class has no subclasses

This method cannot be replicated when used in a modified method.

The same attribute value cannot be changed when used to decorate a property

Abstract class, when there is an abstract method, the class is an abstract class that needs to be added with the abstract modifier, and the abstract method must be overridden by the subclass that inherits it.

Interfaces can be implemented in many ways and can be understood as a special class, except that the class consists of constants and common abstract methods.

Interface demo{public   static final int. age = ten;   public abstract void Tell ()   {}}interface demo2{public  abstract void Say () {}}//An interface can inherit multiple interfaces, Compensate for the lack of single inheritance interface Demo3 extends Demo,demo1{}class m{public    abstract void printf () {}}class A extends M implements de mo,demo2{//must make a copy of the Tell   method public   void Tell () {} public      void Say () {}}class go{public   static void main ( String[] args)  {      a a=new a ();      A.tell ();      A.say ();      A.printf ();  }}

An interface can implement single-inheritance superclass, but can inherit the interface, can compensate for the lack of single inheritance

A class can inherit multiple interfaces, single-inheritance superclass

The difference between an interface and an abstract class:

The inheritance interface must replicate all of the methods inside, and the interface is not private variables or methods, but the abstract class can have its own private variables or methods, but also must be a copy of the abstract methods, others can see the needs of the program to be properly replicated.

About the final keyword and abstract class, interface

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.