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