newb here, I've got following code and was wondering how to grasp the class-concept.
I realize I cannot call a non-static method from main. So what exactly is it I am doing here instead? calling the isSameName
-method through an object of the non-static Person-class, through the main-method? I also don't understand the relationship between the class-objects, as my object kira
is not relevant, but can still use it to call the method with my relevant parameters
class Person {
private String name;
private int alter;
public Person(String name, int alter) {
this.name = name;
this.alter = alter;
}
public String getName() {
return name;
}
public int getAlter() {
return alter;
}
public boolean isSameName(Person a, Person b) {
return a.getName() == b.getName();
}
public static void main(String[] args) {
Person tom = new Person("Tom", 23);
Person kira = new Person("Kira", 34);
Person tim = new Person("Tom", 45);
System.out.println(kira.isSameName(tom, tim));
}
}
would be grateful for any help, and sorry if questions like this were asked a thousand times, I still have problems finding the right words for my search, as I don't know how to even call my problems