AP Computer Science 2.4 Classes and Objects
Recommendation
Want a study guide too?
AP Computer Science: Classes and Objects Drill 2, Problem 4. Which of the following is not a legal method call?
AP | AP Computer Science |
AP Computer Science | Classes and Objects |
Computer Science | AP Computer Science |
Language | English Language |
Program Analysis | Program correctness |
Test Prep | AP Computer Science |
Transcript
Which of the following is not a legal method Call
shmoop yeah but near the potential Answer a lot of
roman numerals and remember roman soldier of walk into a
bar with girlfriend orders five years Okay sounds like we're
being asked which of the given method calls art in
fallon But what on earth are method calls and when
will you ever use it Well typically large java project
will be split up into separate classes classes to make
code more manageable We might have one class handling saving
and loading a file another class handling networking class handling
graphics and so on That way when there's a bug
in a certain function or the code needs to be
modified all the relevant code is in one place The
main class will then call various methods from other classes
is needed right Well small programming projects may not need
so many separate classes but as things get more complicated
while it helps a great deal the thing about how
small company might be if just one or two people
handled everything in a garage Well that's perfectly manageable because
the relatively small operation with a little work to do
but a large company of dozens or hundreds of people
would have to be split into departments each with different
tasks like think about how hard it is for amazon
the ship product right And when it's time to do
something with the same marketing you'd have to give him
a call Yes hello marketing department We need to get
our name out there and i'm thinking pigeon sweaters will
put thousands of tiny sweaters on pigeons all over the
city with our branding all over them they'll be everywhere
can fail right We're calling elsewhere to make a request
is the same thing we're doing with method calls Yes
with fewer pigeon sweat and now let's look at our
options and figure out which are invalid Option one tries
to call a method with object see but see is
just a null object and hasn't been specified as a
new anything so option one won't work at all Option
two tries to call the shed leaves method with object
b which looks like it's gonna work Object is in
oak object and the shed leaves method resides within the
class Looking good Option to option three tries to call
the shed leaves method with object a but a is
a pine object The pine class doesn't contain a shed
leaves method It's only got shed needles Option three is
not going to cut it That makes our answer D
because options one of three are invalid and so our 00:02:55.383 --> [endTime] pigeon sweaters