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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started