Inheritance of Java

Source: Internet
Author: User

1. Syntax

Class Subclass extends Parent class

2. Overriding the method

Write one more method to rewrite

3. Final use

Use final keyword to identify "final" meaning

Final can modify classes, methods, properties, and variables

Modifier classes are not inherited

The modification method cannot be overridden

The Modifier property is not automatically assigned the initial value and must be manually assigned

Modifier variables can only be assigned once, that is, constants

4. Use of Super

Used inside an object, you can represent the parent class object

Explicitly used in the build method only in the first row

If the subclass does not explicitly call the parent class build method, and the parent class does not have a parameterless build method, the error will be

5. Object class

5.1. ToString () method

The hash code (object address string) of the object returned when defining the ToString () method inside the object class

System.out.println (Class); Return memory address

You can represent the properties of an object by overriding the ToString () method

menu, Source--Generate toString () ...

5.2. Equals () method

Compares whether a reference to an object points to the same memory address

if (class. Equals (Class 2)) {:}

You can compare the values of two objects consistently by overriding the Equals () method

menu, Source, Generate hashcode () and Equals () ...

Inheritance of Java

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.