Consider the following classes:
class Box
{
private bool isLidOpen;
public Box()
{
isLidOpen = true;
}
public void OpenLid()
{
isLidOpen = true;
}
public void CloseLid()
{
isLidOpen = false;
}
}
class LockableBox : Box
{
private bool isLidLocked;
public LockableBox()
{
isLidLocked = false;
}
public void LockLid()
{
isLidLocked = true;
}
public void UnlockLid()
{
isLidLocked = false;
}
}
List all the public members of LockableBox.
Below are the list of public members of LockableBox
public LockableBox();
public void LockLid()
public void UnlockLid()
Note : If you like my answer please rate and help me it is very Imp for me
Consider the following classes: class Box { private bool isLidOpen; public Box() { isLidOpen =...
Consider the following classes: class Box { private bool isLidOpen; public Box() { isLidOpen = true; } public virtual void OpenLid() { isLidOpen = true; } public virtual void CloseLid() { isLidOpen = false; } } class LockableBox : Box { private bool isLidLocked; public LockableBox() { isLidLocked = false; } public void LockLid() { isLidLocked = true; } public void UnlockLid() { isLidLocked = false; } public...
Question 19 Given the following class: public class Swapper ( private int x; private String y public int z; public Swapper( int a, String b, int c) ( x-a; y b; zC; public String swap() ( int temp -x; x-z z temp; return y: public String tostring() ( if (x<z) return y: else return" +x+z What would the following code output? Swapper r new Suapper( 5, "no", 10); System.out.printin( r. swap ) ): no no510 510 e 15 Question 20...
Consider the Automobile class: public class Automobile { private String model; private int rating; // a number 1, 2, 3, 4, 5 private boolean isTruck; public Automobile(String model, boolean isTruck) { this.model = model; this.rating = 0; // unrated this.isTruck = isTruck; } public Automobile(String model, int rating, boolean isTruck) { this.model = model; this.rating = rating; this.isTruck = isTruck; } public String getModel()...
Assume Doctor Class is Following:
class Doctor
{
private String fullName;
private String registryNumber;
private String specialty;
public Doctor(String fullName, String registryNumber, String
specialty)
{
this.fullName = fullName;
this.registryNumber = registryNumber;
this.specialty = specialty;
}
public String getName()
{
return fullName;
}
public String getRegistryNumber()
{
return registryNumber;
}
public String getSpecialty()
{
return specialty;
}
public void setName(String fullName)
{
this.fullName = fullName;
}
public boolean equals(Doctor other)
{
if(registryNumber == other.registryNumber)
return...
Write Junit Test for the following class below: public class Turn { private int turnScore; private Dice dice; private boolean isSkunk; private boolean isDoubleSkunk; public Turn() { dice = new Dice(); } public Turn(Dice dice) { this.dice = dice; } public void turnRoll() { dice.roll(); if (dice.getDie1Value() == 1 || dice.getDie2Value() == 1 && dice.getLastRoll() != 2) { turnScore = 0; isSkunk = true; } else if (dice.getLastRoll() == 2) { turnScore = 0; isDoubleSkunk = true; } else { ...
(Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...
public class Scheduler { private List<Course> classes; private List<Student> students; public Scheduler() { classes = new ArrayList<Course>(); students = new ArrayList<Student>(); } public void addCourse(Course course) { this.classes.add(course); } public List<Course> getCourses() { List<Course> newCList=new ArrayList<>(); for(int i=0;i<classes.size();i++){ newCList.add(classes.get(i)); } return newCList; } public void addStudent(Student student) { this.students.add(student); } ...
Consider the class as partially defined here: //class Pizzaorder class Pizzaorder // static public members public static final int MAX TOPPINGS 20: // instance members private String toppings[]; private int numToppings; // constructor public PizzaOrder () { numToppings toppings 0; String[MAX TOPPINGS]; new // accessor tells # toppings on pizza, i.e., #toppings in array public int getNum Toppings ()return numToppings; // etc. We want to write an instance method, addTopping) that will take a String parameter, topping, and add it...
Question 1 Consider the following code snippet: public class Box<E> { private E data; public Box() { . . . } public void insert(E value) { . . . } public E getData() { . . . } } What will result from executing the following code? Box<String> box = new Box<>(); . . . box.insert("blue Box"); String b = box.getData(); A. run-time error B. compiler warning C. no error D. compiler error Question 2 What is used as a...
Consider the following Java classes: class A{ public int foo () { return 1; } public void message () { System.out.println( "A" + foo()); } } class B extends A { public int foo() {return 2; } } class C extends B { public void message () { System.out.println( "C" + foo()); } } (i) What are the outputs of the following code? (ii) What would be the outputs if Java used static dispatching rather than dynamic dispatching? B b...