AP Computer Science 1.1 Standard Data Structures
Recommendation
Want a study guide too?
AP Computer Science 1.1 Standard Data Structures. Which of the following method calls will result in an error?
AP Computer Science | Standard Data Structures |
Program Analysis | Debugging |
Transcript
bessie for which of the following method calls will result
in an error and hear of potential answers Roman numerals
there Well this questions asking us about calling methods which
is pretty much a day to day thing in java
By now you've probably read a bit about classes relationships
and methods and could take a stab this question but
let's fully go over the nature of what we're dealing
with Imagine the following a super class vehicle which branches
down with a few subclass is called minivan motorcycle and
bicycle vehicle would contain members that could be useful tow
any type of vehicle number of wheels propulsion method whatever
you need Really the methods in the minivan class would
be specific to minivan objects Open sliding door full down
rear seats insist i am still cool it's on a
ce faras our question goes it's asking us which of
the attempts to call the method print mu will not
work well The question by design doesn't give us complete
information so we'll have to make a couple educated guesses
based on programming conventions for one will assume that animal
is a super class and that cow is a subclass
of it seems likely that animal and cow have an
inheritance or is a relationship since cow is a gn
animal and second will assume that print mu is a
method belonging to cow rather than the annals Not every
animal moves but most are all cows do so with
that in mind and with our snippet of code that
creates an animal object as a and a cow object
is b which of these attempts at calling print move
will not work We'll attempt one looks good b is
our cow object and this line calls the print moon
method appropriately attempt to looks a little weird What with
these parentheses all over the place we're casting b to
an animal and trying to call print move on it
Even though b is a cow the computer thinks it
is an animal because we've cast it so it'll give
us an error because print move doesn't exist in the
animal class In ten three uses object a an animal
without casting It is a cow so no dice there
One is a legal call but two and three or
not that means our answer is a hay If you
heard about the platypus that called customer service yeah he 00:02:37.935 --> [endTime] couldn't figure out why he got a bill