201671010101 2016-2017-2 "Java Programming"

Source: Internet
Author: User
Tags modifiers

Let's tidy up the various access permission modifiers:

Access permission modifiers The same class Same package Sub-class Global scope
Public
Protect X
Private Χ X X
No modifier (default = Friendly) X X

this week learned to inherit, to know the relationship between the subclass and the parent class, and the difference and connection between them. In inheritance, extends represents the inheritance relationship between subclasses and parent classes. A class that already exists is called a superclass, base class, or parent class, the new class is called a subclass, a derived class, or a child class, and the subclass has a hierarchy and inherits all the members of the parent class, in addition to being richer than the functionality owned by the superclass. Note that in subclasses you can add fields, add methods, or override methods of a superclass, but you must never delete any of the inherited fields and methods. If the parent class requires that the child class is not satisfied, the subclass overrides the parent class.

Super after Plus (), indicates to call the parent class constructor, if Add. Indicates that the parent class member and method are called, and Java does not support multiple inheritance.

The final modifier modifies three parts: 1. Modifying a domain 2. Modifier Class 3. Decoration method, final cannot form an inheritance chain, there is no child class. In the process of using subclasses and parent classes, it is important to enforce type conversions, because subclasses and parent classes, when setting object variables, are set according to their own requirements, and when assigning a parent class object to a subclass, they should unify their object variables. If the type conversion is unsuccessful, the compiler does not make the conversion, and Java does not generate a null object, but throws an exception.

Abstract class: In order to improve the clarity of the program, the class containing one or more abstract methods must itself be declared abstract, and the abstract method acts as a placeholder for their specific implementation in subclasses. Abstract classes cannot be instantiated, meaning that if a class is declared abstract, the object of the class cannot be created, for example: New Person ("Vince Vu") is wrong, but you can create an object of a specific subclass.

If the superclass is not explicitly indicated, object is assumed to be a superclass of this class, and any class can use the object class because they are inheritance relationships.

This week's experiment class with Jaiaju sit together, overcome the lack of the teacher steps, what problems they will be patient to teach me, feel to find a good little teacher. Their learning atmosphere is very good, it can lead others to follow the study, feeling not so very difficult before. Continue to be on their par.

201671010101 2016-2017-2 "Java Programming"

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.