Question: QUESTION6) EXPLAIN EXPLICIT AND IMPLICIT TYPE CASTING WITH EXAMPLE IN THE CONTEXT OF POLYMORPHISM. QUESTION7) a novice programmer writes the following code in order to
QUESTION6) EXPLAIN EXPLICIT AND IMPLICIT TYPE CASTING WITH EXAMPLE IN THE CONTEXT OF POLYMORPHISM.
QUESTION7) a novice programmer writes the following code in order to be able to compleely clone an object of type Car.
public class Tyre{
private int tread Remaining;
public void setTread(int t){
treadRemaining=t;
}
public int getTread(){
Return treadRemaining;
}
}
Public class Car extends Vehicle implements Cloneable{
Private Tyre tyres[]=new Tyre[4];
public Car(){
for(int i=0;i<4;i++);
tyres[i]=new Tyre();
}
}
Public Object clone()throws Clone Not Supported Exception{
Car c= new Car();
c.tyres= this.tyres;
return c;
}
}
a) identify the type of interface that Cloneable is. what is the defining characteristic of such interfaces?
b)identify for which Object Oriented property allows the clone() method to return a reference type of Car?explain briefly.
c)identify and explain why this code may not function as intended?
d)rewrite the code for clone() method to address the problem you have identified and allow Car objects to be fully cloned i.e. allow deep copy.
QUESTION 8) the ''Tool" class has a constructor Tool (int) used to initialize the "lenght" in inches of any tool. the "Hammer" class is a subclass of "Toll". it has an instance variable of Type double named " power" that indicates the amount of hitting force that the hammer can generate. give UML diagram of Tool and Hammer. write the class of Tool and Hammer. be sure to implement the Hammer constructor that initializes the Hammer's "length" and "power" . be sure to make use of the Tool(int) constructor . also, write the Hammer class method display(0 that prints the Hammer's power and then invokes the overridden Tool method display() to print the rest of the information about the Hammer.
a) draw the complete UML diagram of these classes and clearly specify their relation
b) write the java codes for Tool class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
