Question 1 Consider the following code snippet: anEmployee = new Programmer()anE
ID: 3830156 • Letter: Q
Question
Question 1
Consider the following code snippet:
anEmployee = new Programmer()anEmployee.increaseSalary(2500)If the Programmer class inherits from the Employee class, and both classes have an implementation of the increaseSalary method with the same set of parameters, which statement is correct?
Question options:
An additional line of code must be added to the snippet shown previously to specify which method will execute.
It is not possible to determine which class's method will be executed without seeing the complete class definitions.
The increaseSalary method of the Employee class will be executed.
The increaseSalary method of the Programmer class will be executed.
Question 2
Which of the following statements is true? Question options:
A method that is overridden in a subclass can perform a task that is totally different from the task performed by the same method in the superclass.
A method that is overridden in a subclass cannot invoke the method in the superclass with the same name.
A method that is overridden in a subclass must extend the functionality of the superclass by invoking the superclass method.
Every method in a subclass must override a superclass method.
Question 3
If a class has an abstract method, which of the following statements is NOT true?
Question options:
You cannot inherit from this class.
You cannot construct an object from this class.
You can construct an object from this class.
All non-abstract subclasses of this class must implement this method.
Question 4
Which of the following statements about abstract methods is true?
Question options:
An abstract method has a name and parameters, but its implementation is not specified.
An abstract method has parameters and is fully implemented, but it has no defined name.
An abstract method has a name and is fully implemented, but it has no parameters.
An abstract method has only a name, but it implementation is not specified and it has no parameters.
Explanation / Answer
1. Super class variable can refer to subclass object. This is called dynamic polymorphism. Here
Employee anEmployee = new Programmer();
since we are invoking anEmployee.increaseSalary(2500) , the method in the Programmer class will be executed
2. a. Overriden method in the subclass can have its own implementation.
3. a. We can extend the abstract class.
c. Abstract classes can't be instantiated. We can't create a new object for an abstract class
4. a. Abstract method has name and parameters, but not body. It will be implemented in the class which inherits the abstract class.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.