Lang packet Knowledge Point (iii) object class

Source: Internet
Author: User

Object class

1, the class system in Java follows a single structure, that is, any one class goes up to the same parent class;2.Object classIs the root of this single root system, which means it is the common parent of all other classes; 3, ifThe user-defined class does not extend any other class, the default extension is from the object class 4. Some methods defined in the object class are inherited into all classes common methods of the object class
// determines whether the current object is equal to the parameter obj (content) and, if necessary, overrides the method in a custom class Boolean equals (Object obj) // returns the string representation of the current object and, if necessary, overrides the method in the custom class String toString ()

ToString instance:

classStudent {//defines the student class, which inherits from the object class by default  PrivateString Mname; Private intMAge;  PublicStudent (String name,intAge) {//Construction MethodMname =name; MAge=Age ; }     PublicString toString () {//overriding the ToString method in the object classString str = "Name:" + Mname + ", Age:" + MAge + "year old"; return(str); }} Public classTostringdemo {//accommodates the Main method   Public Static voidMain (string[] args) {Student std=NewStudent ("Zhang San", 18);  SYSTEM.OUT.PRINTLN (STD); //default call to ToString method  }}

Lang packet Knowledge Point (iii) object class

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.