I have overriden the method toString() in class Person, but i cant use it in my main method - "Cannot make a static reference to non-static method toString() from the type Object"
class Person {
private String name;
private int id;
public Person(String name,int id) {
this.name = name;
this.id = id;
}
@Override
public String toString() {
String result = "Name: "+this.name+" ID: "+this.id;
return result;
}
}
public class Testing {
public static void main(String[] args) {
Person person = new Person("Ivan",1212);
System.out.println(toString()); // Cannot make a static reference to non-static method
}
}
How can i fix this ?