2024) : Pharmacology For Nursing Practice -
Chamberlain
1). Consider the counter class below.
public class counter
{
public int count = 0;
public int getcount()
{
return count;
}
public void increment()
{
count++;
}
}
using the class above and the variables declared below, what is the value of
num1.equals(num2)?
counter num1 = new counter();
counter num2 = new counter();
true
false
nothing since equals is not defined for counter
a syntax error
Ans: false
2). Consider the following code snippet:
public void deposit(double amount)
{
PaperStoc.com Page 1 of 36
, transactioncount++;
super.deposit(amount);
}
which of the following statements is true?
this method will call itself.
this method calls a public method in its subclass.
this method calls a private method in its superclass
this method calls a public method in its superclass.
Ans: This method calls a public method in its superclass.
3). Consider the counter class below.
public class counter
{
public int count = 0;
public int getcount()
{
return count;
}
public void increment()
{
count++;
}
}
using the class above and the variables declared below, what is the value of
num1.equals(num2)?
counter num1 = new counter();
counter num2 = num1;
true
false
nothing since equals is not defined for counter
a syntax error
PaperStoc.com Page 2 of 36
, Ans: false
4). What is a class called that represents the most general entity in an inheritance hierarchy?
default class.
superclass.
subclass.
inheritance class.
Ans: Superclass.
5). Suppose the class value is partially defined below
public class value
{
private int number;
public int getvalue()
{
return number;
}
}
a subclass of value, largervalue, is defined with a getvalue method that returns twice the
value of the parent. which line is the body of largervalue's getvalue method?
return getvalue() * 2;
return super.getvalue() * 2;
return number * 2;
return super.number * 2;
Ans: return super.getValue() * 2;
6). To ensure that an instance variable can only be accessed by the class that declared it, how
should the variable be declared?
PaperStoc.com Page 3 of 36
, public
private
protected
final
Ans: private
7). Consider the following code snippet:
employee programmer = new employee(10254, "exempt");
string s = programmer.tostring();
assume that the employee class has not implemented its own tostring() method. what
value will s contain when this code is executed?
s will contain the values of the instance variables in programmer.
s will contain only the class name of the programmer object.
s will contain the class name of the programmer object followed by a hash code.
this code will not compile.
Ans: s will contain the class name of the programmer object followed by a hash code.
8). Consider the classes shown below:
public class parent
{
public void dosomething() // method 1
{ /* implementation not shown */ }
}
public class child extends parent
{
public void dosomething(int n) // method 2
{ /* implementation not shown */ }
public void dosomething() // method 3
{ /* implementation not shown */ }
}
if the variable kid is defined below, which version of the dosomething method can be called
PaperStoc.com Page 4 of 36