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 =...
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...
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...
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...
public class CharNode{ private CharNode link; private char info; public CharNode(char info) { this.info = info; this.link = null; } public CharNode(char c, CharNode link) { this.info = info; this.link = link; } public CharNode getLink() { return link; } public void setLink(CharNode link) { this.link = link; } public char getInfo() { return info; } public void setInfo(char info) { this.info = info; } } //Remember Queue is a first-in-first-out data structure public class CharQueue { // front is...
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...