Object Class
Object Class
package com.test;
public class Test {
System.out.println(test.getClass().getSimpleName());
}
}
Output-
com.test.Test
Test
Note- The most of java native method are written in c or c++ that why not able
show the body.
Example
package com.test;
public class Test1 {
Example-1
package com.test;
int empId;
String empName;
System.out.println(test3.equals(test4));
}
}
Output
False
package com.test;
int empId;
String empName;
test3 = test4;
System.out.println(test3.equals(test4));
}
}
Output
True
package com.test;
int x;
}
}
Output
first object is>>50
second object is>>com.test.Test4@7852e922
Here, second output line, we will get address instead of value. To solve this issue,
we should override toString method.
Example-2
package com.test;
int x;
@Override
public String toString() {
return "Test4 [x=" + x + "]";
}
}
Output
first object is>>50
second object is>>Test4 [x=50]
package com.test;
int id;
String employeeName;
String employeeCity;
@Override
public String toString() {
return "Employee [id=" + id + ",
employeeName=" + employeeName + ", employeeCity=" +
employeeCity + "]";
}
System.out.println(employee);
}
}
Output
Employee [id=10, employeeName=ajay, employeeCity=pune]