Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions