Question: When I put this code into eclipse, it says that the class Person is already defined. I am following a tutorial online, and it works

When I put this code into eclipse, it says that the class Person is already defined. I am following a tutorial online, and it works for the instructor. Can someone tell me what I am doing wrong?

class Person {

String name;

int age;

void speak() {

System.out.println("My name is: " + name);

}

int calculateYearsToRetirement() {

int yearsLeft = 65 - age;

return yearsLeft;

}

int getAge() {

return age;

}

String getName() {

return name;

}

}

public class App {

public static void main(String[] args) {

Person person1 = new Person();

person1.name = "Joe";

person1.age = 25;

person1.speak();

int years = person1.calculateYearsToRetirement();

System.out.println("Years Till Retirement: " + years);

int age = person1.getAge();

String name = person1.getName();

System.out.println("Name is: " + name);

System.out.println("Age is: " + age);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!