Java Classes and objects

Source: Internet
Author: User

1. Access rights for classes
The same class Same package Sub-classes under different packages Non-subclasses under different packages
Private
Default
Protected
Public

2.4 Modifier final static This super

1.final

The modifier base type value cannot be changed;

The modified reference type reference cannot be changed, and the object of the invocation can be changed;

The modification method prevents inheritance modification;

The adornment class blocks inheritance.

2.static

Modifying properties and methods allows a class or method to follow a class without having to rely on an object.

3.this

1. In the class method, represents a reference to the method caller object.

2. In the first sentence of the constructor, the constructor that corresponds to the argument is called.

4.super

The child class maintains a reference to the parent class.

3. Reload vs Rewrite

Overloading: Is the same class, the method name + parameter list is different (parameter type and order);

Rewriting: The abortion relationship between the parent class and the subclass;

Subclasses inherit the parent class, which can be overridden, but the method name, parameter list, and return value need to be the same;

Child, the child class modifier cannot be less than the parent class. (The parent class would have public a method, but the subclass becomes private and destroys the consistency)

Java Classes and objects

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.