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 override void CloseLid()
{
if (isLidLocked == false)
base.CloseLid();
}
public override void OpenLid()
{
if (isLidLocked == false)
base.OpenLid();
}
}
List the values of the data members for each object at the end of the following code:
LockableBox a = new LockableBox();
a.CloseLid();
a.LockLid();
Box b = a;
b.OpenLid();
// Here: what is the internal state of each object?
There is only one object here, with 2 different references. Status of object: ------------------- isLidLocked -> True isLidOpen -> False both references a and b are pointing to the above object.
Consider the following classes: class Box { private bool isLidOpen; public Box() { isLidOpen =...
c++ Part 1 Consider using the following Card class as a base class to implement a hierarchy of related classes: class Card { public: Card(); Card (string n) ; virtual bool is_expired() const; virtual void print () const; private: string name; Card:: Card() name = ""; Card: :Card (string n) { name = n; Card::is_expired() return false; } Write definitions for each of the following derived classes. Derived Class Data IDcard ID number CallingCard Card number, PIN Driverlicense Expiration date...
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...
The current code I have is the following: package uml; public class uml { public static void main(String[] args) { // TODO Auto-generated method stub } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...
The method m() of class B overrides the m() method of class A, true or false? class A int i; public void maint i) { this.is } } class B extends A{ public void m(Strings) { 1 Select one: True False For the following code, which statement is correct? public class Test { public static void main(String[] args) { Object al = new AC: Object a2 = new Object(); System.out.println(al); System.out.println(a): } } class A intx @Override public String toString()...
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...
For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() { super(); System.out.println(“B() called”);...
For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() { super(); System.out.println(“B() called”); } public...
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); } ...
Question 16 You must put your data in classes if you use C++. True False 2 points Question 17 Constructors are automatically invoked during class instantiation. True False 2 points Question 18 To make your data accessible to entities outside of your class, declare the members of that class as private. True False 2 points Question 19 You can make arrays of built-in types like int and double, but not of user-defined types. True False 2 points Question 20 One...
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()...