51CTO Big Data Learning 003-abstract classes, interfaces, inner classes

Source: Internet
Author: User

I finished the seventh day of big data today. Summarize the contents of the abstract class, interface, inner class.

The use of the interface can reduce the coupling of the code, abstract class, embodies the object-oriented characteristics of Java programming. Only single inheritance is supported in Java, that is, each class can inherit only one ancestor parent class, but it can be passed. Interfaces can be implemented more than one, which also implements multiple inheritance of classes from another perspective.

The implementation interface uses the keyword implements, and the abstract class uses the abstract keyword. The methods in the interface are all abstract methods, and abstract classes can have abstract methods or no abstract methods. Abstract classes cannot be instantiated. Subclasses inherit abstract classes and need to implement the abstract methods in the parent class. interface, all of the methods are decorated with public (not write is also public), because the interface is to provide the template for the outside world, need to be implemented by other classes, if the interface method is decorated as private or protected, the other class implements the interface, the method is not accessible, Lost the meaning of implementing the interface. When an interface is to be implemented, the methods defined in the interface must be defined as public, otherwise, they will only get the default package access, so that in the process of inheriting the method, the access permissions are reduced, which is not allowed by the Java visit compiler. In other words, the access rights of the methods in the interface can only be enlarged, not reduced, can be carried forward, not pocketed. The fields defined in the interface are hidden, decorated as static and final.

You can place the definition of one class inside the definition of another class, which is the inner class.

If you want to create an object of an inner class from anywhere other than the non-static method of the outer class, you must specifically indicate the type of the object, as in the main () method: Outerclassname.innerclassname. An inner class object can access all members of its outer class object.

51CTO Big Data Learning 003-abstract classes, interfaces, inner 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.