Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. True or False – Interface types can include some full method implementations.

ID: 3728555 • Letter: 1

Question

1. True or False – Interface types can include some full method implementations.

2. True or False – If Car extends Vehicle, then Vehicle v = new Car(); is correct code.

3. True or False – UML has an arrow that represents the Java extends concept.

4. Complete the class BikePart such that it correctly implements Cost.

   public interface Cost {

     public double getCurrentCost();

     public boolean isOnSale();

   }

   public class BikePart implements Cost {

     private String name;

     private double regularPrice, salesPrice;

     private boolean onSale;

     public BikePart(String n, double rp, double sp, boolean os) {

       name = n; regularPrice = rp, salesPrice = sp,>

     }

}

5. Why does Java include both Comparable and Comparator interfaces (instead of just providing one or the other)?

6. Consider the following class Room.

public class Room {

   private String roomNumber, buildingName, capacity;

   public Room() { capacity = 0; }

   public Room(String rn, String bn, int c) {

      roomNumber = rn, buildingName = bn, capacity = c;

   }

   public setRN(String rn) { roomNumber = rn; }

   public String getRN() { return rn; }

   … more code …

}

For TrinkleRoom that extends Room, which of the following fields should or should not be included? Explain your answer.

public class TrinkleRoom extends Room {

   private String roomNumber, buildingName, capacity;

   private String department;

   private boolean isLab;

   … more code …

}

Explanation / Answer

If you post more than 1 question, as per chegg guidelines i have to solve only 1 question.

Ques 1. True

As per the new Java rules, the methods in the interface can also have a body. So, we can implement full methods in an interface.

Ques 2. True

A variable or super class can refer to the class inheriting the super class. But it can only invoke the methods in the suer class.