TRUE or FALSE: The only way a class may have a superclass is by using the extend
ID: 3705381 • Letter: T
Question
TRUE or FALSE: The only way a class may have a superclass is by using the extends keyword at the start of the class.
Write a line of code to specify that a class named PieceWorker inherits from a class named Employee.
Write a line of code that calls superclass Employee's toString method from subclass PieceWorker's toString method.
Write a line of code that calls superclass Employee's constructor from subclass PieceWorker's constructor; assume that the superclass constructor receives three Strings representing the first name, last name, and social security number
Write two classes that extend the Student class from question 1. (Assume that the three overloaded constructors are in the Student class, and that public getters and setters have been written for the instance variables.) The first subclass should be named UndergraduateStudent. This class must include instance variables for the name of the high school the student attended and the student's SAT score; create public getters and setters for these instance variables. The second subclass should be name GraduateStudent. This class must include an instance variable for the name of the college where the student earned a Bachelor's degree; create a public getter and setter for this instance variable. Finally, each subclass must have a single constructor that accepts the student's name. Ideally, this should utilize one of the Student superclass's constructors.
Explanation / Answer
Please find the answers below:
#
Mostly True. When we talk about explicitly stating a superclass by using the "extends" keyword at the start of the class, then the statement is true.
Note that: An Object class is the superclass for a class implicitly; without writing the extends keyword at the start of the class. Every class extends java.lang.Object even when the keyword is not specified at the start of the class.
#
public class PieceWorker extends Employee {
#
super.toString()
#
super(firstName,lastName,ssNumber);
Please find the classes below as per the specification:
-----------------------------------------------------
---------------------------------------------------
----------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.