Java note (7) Object class and Object Transformation

Source: Internet
Author: User

Object class is the fundamental class of all Java classes.

If the extends keyword is not used in the class declaration to specify the base class, the base class is the Object class by default.

The Object class defines the public String toSting () method. Its return value is of the String type, which describes the information about the current Object.

When you connect a String to other types of data (for example, System. out. println ("info" + person), The toString () method of the object is automatically called.

You can rewrite the toString () method in the User-Defined type as needed.

Object Transformation

A base class's reference type variable can "point to" its subclass object

The reference of a base class cannot access the newly added member (attributes and methods) of its subclass object)

You can use the reference variable instanceof class name to determine whether the object to which the referenced variable "points" belongs to this class or its subclass.

Subclass objects can be used as base class objects, which are called upcasting, and vice versa)

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.