JAVA 1 Suppose Monster is a Java interface that requires eve
JAVA
1 Suppose Monster is a Java interface that requires every implementing class to contain a method called wreakHavoc(). Yeti is a concrete class that implements Monster and also has a method called stomp(). You run the following code:
Monster m = new Yeti();
Yeti y = new Yeti();
Which of the following is/are valid method calls?
m.stomp();
 m.wreakHavoc();
 y.stomp();
 y.wreakHavoc();
2 Suppose GeometricShape2D is an interface that requires a method called getArea(). Circle is a concrete class that implements GeometricShape2D and also contains a method called getCircumference(). You create a variable of type GeometricShape2D and make it refer to an instance of Circle. Using the variable, you can run getArea(). Why can\'t you also run getCircumference()?
Circle should not implement GeometricShape2D, it should extend it
 The Java garbage collector destroys the object after you run getArea()
 You can\'t run a method of a concrete class if it is a subclass of an abstract class
 The variable of type GeometricShape2D can only be used to run methods that are available in that class, even if the actual object belongs to a a subclass
 getCircumference() should be static
3 Suppose you are writing an application that will keep track of natural disasters using an DisasterMonitor class that contains an ArrayList of Disasters. Blizzard and Flood each need a method to determine severity level and another to determine predicted duration. These two methods are the only ones needed, and both of them work differently for the two classes. Which of the following approaches is best?
Disaster is a Java interface implemented by Blizzard and Flood
 DisasterMonitor is an abstract class extended by Blizzard and Flood
 DisasterMonitor is a Java interface implemented by Blizzard and Flood
 Disaster is a concrete class with a boolean variable that will be true if the Disaster if a Flood and false if it is a Blizzard
 Disaster is a concrete class extended by Blizzard and Flood
4 Suppose you are writing an application that will be used to control clothes dryers. Each type of Dryer has a heatAir() method, which works differently for GasDryer and ElectricDryer. Each type also has a timer() method, which works the same way for both types of Dryer. Which of the following approaches is best?
GasDryer and ElectricDryer each implement the Java interface Dryer
 GasDryer and ElectricDryer are two unrelated classes
 GasDryer and ElectricDryer each extend the abstract class Dryer
 GasDryer and ElectricDryer each extend the concrete class Dryer
 GasDryer and ElectricDryer are interfaces, implemented by Dryer
5 Suppose Demon and Werewolf are two classes that implement the interface Monster. Which statement(s) is/are correct?
We can instantiate objects of class Monster and add them to a list of Monsters
 A list of Monsters may contain any combination of Werewolves and Demons
 A list of Demons may contain one or more objects of class Demon
 A list of Demons may contain one or more Werewolves
 Any method that is required by the Monster interface can be called by using a variable of type Demon
Solution
1) Here m.stomp(); is the only invalid method
 call since object m is not of type Yeti.
   
 m.wreckHavoc(); is a valid method call since m is an object of Monster and
 wreckHavoc is a method of Monster interface.
 
 y.stomp(); is a valid method call since y is an object of Yeti
 and stomp is method of yeti class.
   
 y.wreckHavoc(); is a valid method call because whenever a class
 implements an interface, all the methods of that interface becomes
 publice members of the implemented class by default. Therefore wreckhavoc can be
 accessed using object of class yeti.
 //here is the complete java program
import java.util.*;
 import java.lang.*;
 import java.io.*;
interface Monster
 {
 public void wreckHavoc();
 }
 class Yeti implements Monster
 {
 public void wreckHavoc()
 {
 System.out.println(\"implementation of wreckhavoc\");
 }
 public void stomp()
 {
 System.out.println(\"implementation of stomp\");
 }
 public static void main(String arg[])
 {
 Monster m = new Yeti();
 Yeti y = new Yeti();
 //m.stomp();
 m.wreckHavoc();
 y.stomp();
 y.wreckHavoc();
 }
 }


