Create a Person class having attributes such as name, address, birthYear, isMarr
ID: 3560771 • Letter: C
Question
Create a Person class having attributes such as name, address, birthYear, isMarried and the corresponding setters and getters. Create two subclasses of the Person class: class Employed and class Student. The Employed class should have an additional static attribute isEmployed set to true and the Student class should have an additional attribute ID. Both subclasses should have setters and getters for the new attributes. Override the equals() method of the Student class to compare the values of the ID attribute. Write a Test class containing the main method in which you create instances of Person, Employed and Student classes and:
- Show how the static attribute isEmployed behaves differently than an instance attribute (for example name)
- Show if two Student instances are equal or not based on your equals() method.
Explanation / Answer
The output left instance method is computed from the string instance provided (in this case myString).
a good examples of a static method is a method to create test objects for your test methods. These methods are simple and don't need to know any "saved" data to compute the output. These methods are fixed (static).
And suppose you want to call the above method in your test code:
Notice two things: