AP Computer Science 1.1 Inheritance, Abstraction, and Polymorphism
Recommendation
Want a study guide too?
AP Computer Science 1.1 Inheritance, Abstraction, and Polymorphism. Which of the following are correct?
AP | AP Computer Science |
AP Computer Science | Inheritance, Abstraction, and Polymorphism |
Computer Science | AP Computer Science |
Language | English Language |
Program Analysis | Program correctness |
Test Prep | AP Computer Science |
Transcript
problem states up arrows indicated inheritance relationship and we already
know that inheritance is just a big fancy word for
is a relationship No fast song is a song slow
song is a song too and we can go step
further and say power ballad is a slow song which
is a song Well we could extend this even further
by saying november rain is a power ballad november rain
than inherits any and all of the fields methods and
nested classes from power ballad which inherits from slow song
which inherits from song for exam song would contain members
that are relevant all songs and every subclass of song
things like are this name instruments song blank and so
on things that every song will have Well november rain
would be extremely specific like emotional axl rose vocal which
is something out every single half aside from simply knowing
their relationship between classes It's also important to know how
to properly declare and create a variable setting it all
up typically goes like this class variable named equals new
glass for supplies Yeah right left side of the equation
declares a variable to refer to An object song a
for example lets the compiler know that you're going to
use a to refer to data of the variety song
but that object doesn't actually yet exist On the other
side of the equation we get down and dirty and
actually a sign an object to that variable A new
power ballad for example would be created with song a
equals new power valid All right the question is asking
us which of these three option for declaring in creating
variables are correct starting with option one song a equals
new power balance and that's what we just did a
second ago and it works too and song be equals
New slow jam Yeah perfectly good way of creating a
slow jam Another good way would involve candles rose petals
and a saxophone solo But this is a little quicker
option One is good Option two is a little weird
It has as creating a slow song and power valid
and having them equal new song and slow song objects
but that's just not gonna fly the left side of
the equation declares variables name and its class and the
right side actually creates the object Option two is trying
to declare a variable of the type that's a subclass
of the actual object or creating that's like declaring that
you're going to be dracula for halloween But he actually
dress up some generic monster The option to option three
works like option one declaring variables and b to be
songs and then creates new fast song and slow song
objects So yeah three work with options One of three
working and to being wrong That makes the our answer