class Human{ // declared instance variables String name; int age; // instance method 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; } // so when I create an instance, i can't have constructor? // error here Human(int age){ age = this.age; } } } public class GettersAndReturnValue { public static void main(String[] args) { // error here because I created a constructor Human(int a) Human human1 = new Human(); human1.name = "Joe"; human1.age = 25; human1.speak(); int years = human1.calculateYearsToRetirement(); System.out.println("Years till retirements " + years); int age = human1.getAge(); System.out.println(age); } } I tried to create a constructor Human(int age) to practice 'this' keyword and to change the age from 25 to something else but I get an error because I have one Human class and one Human constructor. When I try to create an instance of Human Type in my main method, eclipse is asking me to remove the constructor
public Human ( int a ), along withno-args constructor ( if need be )inside theHumanclass, only then you can use that inside themainmethod ofGettersAndReturnValueclass, while creating an object of the class.