I have a main method part of the initiating program, a superclass called Person and subclass called Employee. Person has a couple of attributes: "name" and "age" and Employee has: "department" and "location."
How do I declare or create an instance of Person inside of Employee so Employee could then obtain those attributes?
In the main I'm initiating the program as so...
Person p1 = new Person()
p1.setName("Bob");
p1.setAge("45");
System.out.println(p1); //Prints Bob and 45 via my toString() method.
Employee e1 = new Employee()
e1.setDepartment("Accounting");
e1.setLocation("New York");
System.outprintln(e1); //Prints just department and location via this
class's toString method, which uses @Override.
I've tried creating a constructor which references the Person class, but I get stuck on what to return exactly. I'm brand new to programming and my head is spinning. It's probably something simple that I'm not understanding. Any help is much appreciated.
Edited to add:
So in Employee I've tried:
Person p1 = new Person;
Public p1 setPerson(string name, int age){
}
Do I instead need to invoke individual methods such as
Public p1 setName(){
}
Public p1 getName(){
return name;
}