ShmoopTube

Where Monty Python meets your 10th grade teacher.

Search Thousands of Shmoop Videos


Inheritance, Abstraction, and Polymorphism Videos 17 videos

AP Computer Science 1.2 Inheritance, Abstraction, and Polymorphism
369 Views

APCS: Inheritance, Abstraction, and Polymorphism Drill 1, Problem 2. Which of the following is the correct way to begin writing your class?

AP Computer Science 1.1 Inheritance, Abstraction, and Polymorphism
203 Views

AP Computer Science 1.1 Inheritance, Abstraction, and Polymorphism. Which of the following are correct?

AP Computer Science 1.3 Inheritance, Abstraction, and Polymorphism
177 Views

AP Computer Science 1.3 Inheritance, Abstraction, and Polymorphism. Which of the following is true?

See All

AP Computer Science 3.1 Inheritance, Abstraction, and Polymorphism 20 Views


Share It!


Description:

Here we're looking for the correct implementation of the "compareTo" function. Shall we compareTheeTo a summer's day? Eh, probably not a bad idea. Flattery will get us everywhere.

Language:
English Language

Transcript

00:04

And here's your shmoop du jour brought to you by the most

00:06

[Man transforms apple and christmas tree into pineapple] Christmassy of apples the pineapple consider the following code segments

00:19

assume that red and green are the only two apple colors and green apples are

00:24

better than red apples due to their superior taste and crunch do agree that

00:28

golden delicious apples are actually the best but that doesn't fit into this [Man throws away golden apple]

00:31

logic so we'll keep it simple and show Granny Smith some love.. The compare to

00:37

function should return a positive value if the Apple is better than the other

00:41

Apple a negative value if the Apple is better and zero if the two apples are

00:47

equal i.e they're of same color well which of the following is a correct

00:51

implementation of the compared to function we can already eliminate choice

01:00

A and B they return a string minus a string the return type of the Apple

01:04

compared to must be an int so the other three choices are similar to each

01:08

other let's break them down. Choice E returns a negative value of the

01:12

comparison between the string value of the other color and the apple color this

01:17

means that the Apple color was green in the other color was red the string [Green and Red apples appear in a kitchen]

01:20

compared to would return a positive value the Apple compared to then returns

01:25

the opposite of this value in this case we're turning a negative value we want a

01:29

positive value returned if the apples green all right so choice D compares the

01:33

string value of the apple color to the other color but the apple color with [Green and Red apple in a bowl]

01:37

green and the other was red. This would return a negative value this is also

01:40

incorrect choice C compares string value of the apple color to the other

01:45

colors, this would return a negative value if the apple color was green and the other

01:49

was red but the Apple compareto method returns the opposite of this value this [person punches negative value off a table]

01:54

would be a positive value which is exactly what we want, so answer C...

01:59

next time we'll explore another cool crossbreed..snape ple yeah remember that

02:04

guy... [Snape and apple transform into snapple bottle]

Related Videos

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

AP Computer Science 1.4 Standard Algorithms
200 Views

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
191 Views

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
204 Views

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
191 Views

AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?