-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoStringmethod.java
More file actions
24 lines (23 loc) · 813 Bytes
/
Copy pathtoStringmethod.java
File metadata and controls
24 lines (23 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class toStringmethod
{
public static void main(String[] args)
{
Employee emp=new Employee("Martinez","Anthony");
System.out.println("This is a program to describe Object class methods & getClass() method of the Object class is used to determine the name of the class with the extension of getName() method \nAlso, a point to remember that getClass() method returns an object of type of the variable which to which it is referred");
System.out.println(emp.toString());
}
}
class Employee
{
private String lastName;
private String firstName;
public Employee(String lastName,String firstName)
{
this.lastName=lastName;
this.firstName=firstName;
}
public String toString()
{
return "Name of the class:"+this.getClass().getName()+"\nEmployee["+this.firstName+" "+this.lastName+"]";
}
}