ShmoopTube
Where Monty Python meets your 10th grade teacher.
Search Thousands of Shmoop Videos
AP Computer Science 1.1 Standard Data Structures 194 Views
Share It!
Description:
AP Computer Science 1.1 Standard Data Structures. Which of the following method calls will result in an error?
Transcript
- 00:00
Thank you We sneak Then here's your shmoop toos your
- 00:05
brought to you with the explicit promise that will never
- 00:09
use cow puns will milk some utter ting for humor
- 00:14
Consider the following segment of code right there This thing
- 00:17
animal equals new animal best for cab equals new count
Full Transcript
- 00:19
bessie for which of the following method calls will result
- 00:23
in an error and hear of potential answers Roman numerals
- 00:28
there Well this questions asking us about calling methods which
- 00:31
is pretty much a day to day thing in java
- 00:34
By now you've probably read a bit about classes relationships
- 00:36
and methods and could take a stab this question but
- 00:39
let's fully go over the nature of what we're dealing
- 00:41
with Imagine the following a super class vehicle which branches
- 00:45
down with a few subclass is called minivan motorcycle and
- 00:50
bicycle vehicle would contain members that could be useful tow
- 00:53
any type of vehicle number of wheels propulsion method whatever
- 00:57
you need Really the methods in the minivan class would
- 01:01
be specific to minivan objects Open sliding door full down
- 01:05
rear seats insist i am still cool it's on a
- 01:09
ce faras our question goes it's asking us which of
- 01:12
the attempts to call the method print mu will not
- 01:15
work well The question by design doesn't give us complete
- 01:19
information so we'll have to make a couple educated guesses
- 01:22
based on programming conventions for one will assume that animal
- 01:26
is a super class and that cow is a subclass
- 01:30
of it seems likely that animal and cow have an
- 01:33
inheritance or is a relationship since cow is a gn
- 01:37
animal and second will assume that print mu is a
- 01:39
method belonging to cow rather than the annals Not every
- 01:43
animal moves but most are all cows do so with
- 01:47
that in mind and with our snippet of code that
- 01:49
creates an animal object as a and a cow object
- 01:52
is b which of these attempts at calling print move
- 01:55
will not work We'll attempt one looks good b is
- 01:59
our cow object and this line calls the print moon
- 02:01
method appropriately attempt to looks a little weird What with
- 02:05
these parentheses all over the place we're casting b to
- 02:09
an animal and trying to call print move on it
- 02:12
Even though b is a cow the computer thinks it
- 02:14
is an animal because we've cast it so it'll give
- 02:18
us an error because print move doesn't exist in the
- 02:21
animal class In ten three uses object a an animal
- 02:25
without casting It is a cow so no dice there
- 02:29
One is a legal call but two and three or
- 02:31
not that means our answer is a hay If you
- 02:34
heard about the platypus that called customer service yeah he 00:02:37.935 --> [endTime] couldn't figure out why he got a bill
Up Next
AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?
Related Videos
AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?
AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?
AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...
AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?