Question: 2 Given the following class definition: abstract class Teacher{ void showSubject () { out.println(Teaches: ); subject(); } abstract void subject (); } (a) Declare a

2 Given the following class definition: abstract class Teacher{ void showSubject () { out.println("Teaches: "); subject(); } abstract void subject (); } (a) Declare a class TeacherofScience such that the following client-code statement would execute: Teacher t = new TeacherofScience (); (b) Would the following client-code statement execute successfully? Briefly explain why/why-not. Teacher t = new Teacher (); (c) With respect to the abstract void subject () method: i) What is the effect of the keyword abstract to subclasses? ii) From a design point of view, what does the abstract method communicate? (I.e. complete this sentence: "You can't have...".) (d) There are a number of variants (or types) of 'factory'. i) Write a code example of a 'factory method' design pattern and provide client-code statements to show how it would be used. Use the terms get Product and create in your code-sample and ensure you include a subclass. ii) Using the terms 'single' and 'encapsulates': explain the advantage a factory can provide to the design of a software system
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
