,8/9/24, 4:57 AM
Consider the following class definition: b) Redefine addEm to return the value of z+super.addEm(), but leave changeEm alone.
public class AClass
{
protected int x;
protected int y;
public AClass(int a, int b)
{
x = a;
y = b;
}
public int addEm()
{
return x + y;
}
public void changeEm()
{
x++;
y--;
}
public String toString()
{
return "" + x + " " + y;
}
}
You want addEm to now add all three values,
return the sum, and changeEm to change x
and y, but leave z alone. Which should you
do?
a) Redefine addEm and changeEm without
referencing super.addEm() or
super.changeEm().
b) Redefine addEm to return the value of
z+super.addEm(), but leave changeEm alone.
c) Redefine changeEm to call
super.changeEm() and then set z = x + y, but
leave addEm alone.
d) Redefine addEm to return the value of
z+super.addEm() and redefine changeEm to
call super.changeEm() and then set z = x + y.
e) Redefine changeEm to call
super.changeEm() without doing anything to
z, and redefine addEm to return
super.addEm().
2/28
, 8/9/24, 4:57 AM CSCI300 FINAL EXAM Flashcards | Quizlet
Assume that Student, Employee and Retired e) This cannot be determined by examining the code
are all extended classes of Person, and all
four classes have different implementations
of the method getMoney. Consider the
following code where ... indicates the
required parameters for the constructors:
Person p = new Person(...);
int m1 = p.getMoney(); // assignment 1
p = new Student(...);
int m2 = p.getMoney(); // assignment 2
if (m2 < 100000)
p = new Employee(...);
else if (m1 > 50000)
p = new Retired(...);
int m3 = p.getMoney(); // assignment 3
The reference to getMoney() in assignment 3
is to the class:
a) Person
b) Student
c) Employee
d) Retired
e) This cannot be determined by examining
the code
Aside from permitting inheritance, the a) permit access to the protected item by any class defined in the same package
visibility modifier protected is also used to:
a) permit access to the protected item by
any class defined in the same package
b) permit access to the protected item by
any static class
c) permit access to the protected item by
any parent class
d) ensure that the class cannot throw a
NullPointException
e) define abstract elements of an interface
Java does not support multiple inheritance b) implementing interfaces
but some of the abilities of multiple
inheritance are available by:
a) importing classes
b) implementing interfaces
c) overriding parent class methods
d) creating aliases
e) using public rather than protected or
private modifiers
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Denyss. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $7.99. You're not tied to anything after your purchase.