• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 18 pages
Exam (elaborations)

Ap Computer Science Unit 9 Questions And Complete Solutions

Document preview thumbnail
Preview 3 out of 18 pages

AP COMPUTER SCIENCE UNIT 9 QUESTIONS AND COMPLETE SOLUTIONS

Content preview

AP COMPUTER SCIENCE UNIT 9
QUESTIONS AND COMPLETE
SOLUTIONS


Consider athe afollowing aclass adefinitions.
public aclass aBike
{
private aint anumWheels a= a2;

// aNo aconstructor adefined
}

public aclass aEBike aextends aBike
{
private aint anumBatteries;

public aEBike(int abatteries)
{
numBatteries a= abatteries;
}
}
The afollowing acode asegment aappears ain aa amethod ain aa aclass aother athan aBike aor
aEBike.
EBike aeB a= anew aEBike(4);
Which aof athe afollowing abest adescribes athe aeffect aof aexecuting athe acode asegment?
A
An aimplicit acall ato athe azero-parameter aBike aconstructor ainitializes athe ainstance
avariable anumWheels. aThe ainstance avariable anumBatteries ais ainitialized ausing athe
avalue aof athe aparameter abatteries.
B
An aimplicit acall ato athe aone-parameter aBike aconstructor awith athe aparameter apassed
ato athe aEBike aconstructor ainitializes athe ainstance avariable anumWheels. aThe
ainstance avariable anumBatteries ais ainitialized ausing athe avalue aof athe aparameter
abatteries.
C
Because asuper ais anot aexplicitly acalled afrom athe aEBike ac a- a(correct aanswer) a-A

,An aimplicit acall ato athe azero-parameter aBike aconstructor ainitializes athe ainstance
avariable anumWheels. aThe ainstance avariable anumBatteries ais ainitialized ausing athe
avalue aof athe aparameter abatteries.


Consider athe afollowing aclass adefinitions.
public aclass aBird
{
private aint abeakStrength;

public aBird(int ainput)
{
beakStrength a= ainput;
}

public avoid asetBeakStrength(int astrength)
{
beakStrength a= astrength;
}
}

public aclass aHawk aextends aBird
{
private aint atalonStrength;

public aHawk(int atalon, aint abeak)
{
super(beak);
talonStrength a= atalon;
}
}
The afollowing astatement aappears ain aa amethod ain aanother aclass.
Bird ab a= anew aHawk(5, a8);
Which aof athe afollowing abest adescribes athe aeffect aof aexecuting athe astatement?
A
The aBird avariable ab ais ainstantiated aas aa aHawk. aThe ainstance avariable
atalonStrength ais ainitialized awith athe avalue afrom athe aparameter atalon. aThe aHawk
aconstructor acannot aset athe ainstance avariable abeakStrength abecause aa asubclass
adoes anot ahave aaccess ato aa aprivate avariable ain aits asuperclass.
B
The aBird avariable ab ais ainstantiated aas aa aHawk. aThe acall asuper(beak) areturns aa
avalue afrom athe ainstance avariable abeakStrength ain a- a(correct aanswer) a-D
The aBird avariable ab ais ainstantiated aas aa aHawk. aThe acall asuper(beak) ainvokes athe
aBird aconstructor aand ainitializes athe ainstance avariable abeakStrength awith athe avalue
afrom athe aparameter abeak. aThe ainstance avariable atalonStrength ais athen ainitialized
awith athe avalue afrom athe aparameter atalon.

, Consider athe afollowing aclass adefinitions.
public aclass aBook
{
private aString abookTitle;

public aBook()
{
bookTitle a= a"";
}

public aBook(String atitle)
{
bookTitle a= atitle;
}
}
public aclass aTextBook aextends aBook
{
private aString asubject;

public aTextBook(String atheSubject)
{
subject a= atheSubject;
}
}
The afollowing acode asegment aappears ain aa amethod ain aa aclass aother athan aBook aor
aTextBook.
Book ab a= anew aTextBook("Psychology");
Which aof athe afollowing abest adescribes athe aeffect aof aexecuting athe acode asegment?
A
The aTextBook aconstructor ainitializes athe ainstance avariable asubject awith athe avalue
aof athe aparameter atheSubject, aand athen ainvokes athe azero-parameter aBook
aconstructor, awhich ainitializes athe ainstance avariable abookTitle ato a"".
B
The aTextBook aconstructor ainitializes athe ainstance avariable asubject awith athe avalue
aof athe aparameter atheSubject, aand athen ainvokes athe aone-parameter aBook
aconstructor awith atheSubject aas athe aparameter, awhi a- a(correct aanswer) a-C
There ais aan aimplicit acall ato athe azero-parameter aBook aconstructor. aThe ainstance
avariable abookTitle ais athen ainitialized ato a"". aThen, athe ainstance avariable asubject ais
ainitialized awith athe avalue aof athe aparameter atheSubject.


Consider athe afollowing aclass adefinitions.
public aclass aDrink
{
// aimplementation anot ashown
}
public aclass aCoffee aextends aDrink

Document information

Uploaded on
August 28, 2024
Number of pages
18
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$17.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Lectpotter
4.8
(186)
Sold
143
Followers
9
Items
2647
Last sold
6 days ago


Reviews from verified buyers




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions