Java Object-oriented

Source: Internet
Author: User
Tags access properties

First, overload, cover and hide

1. Overloading

Each method has a signature that consists of a method name and a list of arguments, a method that cannot have the same signature in the same class, and a method that is different for the same name but with a parameter list is called an overload.

2. Overwrite

Subclasses can inherit all the methods in the parent class except the constructor method and all the properties, of course, for the parent class of the properties and methods of private, subclass inheritance is also inaccessible;

For instance methods, if a method with the same signature as a method inherited from the parent class appears in the subclass, the method inherited from the parent class is overwritten, and the method in the parent class is overridden in a subclass, and the return type is the same as or its subtype of the method return type in the parent class. Overwrite is used to change the default implementation of a method inherited from a parent class in a subclass;

Subclasses cannot overwrite a private, final, static method in a parent class.

3. Hide

For a property in the parent class, there is no override to say that the concept of overriding is for a method, in which the property in the parent class is hidden if the attribute with the same name in the parent class appears.

4. For private methods, if a method with the same signature in the parent class appears in the subclass, this is not an overlay, in fact the method in the subclass is entirely another new method.

Second, this and super

1. This

Each non-static method in the class has a hidden parameter this,this to the object instance of the current calling method, so the this reference property is often used when the parameter name and the property name of the method are the same;

This also has another usage, which is to invoke the other constructor methods in the class on the first line of the constructor.

2. Super

Super is used to refer to the overridden method in the parent class in the subclass;

Super is used to access properties that are hidden in the parent class in the subclass;

Super is used to invoke the constructor method in the parent class in the first row of the subclass's constructor.

Third, the static keyword

1.static Properties

The static property indicates that all instance objects of a class share the same property, and the static property can be accessed directly from the class name.

2.static method

The static method is a method that cannot be manipulated against an object, and the static method does not have a hidden parameter this, so the object instance cannot be modified, but you can manipulate the static property and invoke other static methods;

The static method can be called directly through the class name, or by an instance object, and the normal method must be called by an instance object;

The static method cannot be overwritten.

Java Object-oriented

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.