(Solved): CSE205 Quiz 5: Inheritance and Polymorphism ...
CSE205
Quiz 5: Inheritance and Polymorphism
1 / 1 pts
T/F? - Private properties are not inherited into a child class.ou Answered
- True
- False
1 / 1 pts
Sometimes inheritance is unnecessary and you should just create a well written Interface instead.
Note: we're talking of Interfaces like Comparable and such, not the "public interface" Correct!
- True
- False
1 / 1 pts
What is true about the protected keyword in terms of inheritance?t!
- Protected items are accessible within the scope of child classes but inaccessible outside to outside scope.
Correct!
- If you don't use protected, you have to rely on the public interface of the parent class to access/use parent functionality
- Protected members of a class have extra security built in via the compiler.
Correct!
- Shockingly ... protected properties and methods are accessible within the scope of anything that shares the package of the class.
This is actually true ... free point ... I forgot to mention this in lecture because I often don't use packages in my sample code for the sake of time. This is a Java feature.
- Protected members are inaccessible in child classes, we use private to make them accessible.
1 / 1 pts
Which of these are an example of polymorphism in the real-world?
- Automobiles
Different cars, while having the same interface can have very different implementations
- Different colors of houses!
- Smart phones
- Radio stations that play different music/formats
This would actually be one class ... only the content really changes.
- The streets in a city
1 / 1 pts
If I want a parent that creates a consistent, reliable set of methods for an inheritance hierarchy, which technique should I use?
- Create and use an Interface
- Keep parent methods private so that children must provide their own public interface
- Provide multiple definitions of the same method to customize functionalityCorrect!
- Create an abstract base class with several methods that are abstract
1 / 1 pts
In Java, which keyword do we use to create a method that has no body that exists only to be overridden by a child?
- virtual
- finalCorrect!
- abstract
- None of these
- interface
1 / 1 pts
Given a class Animal has a child Cat and a child BigCat. Cat has a child class Tabby and BigCat has a child class Tiger.
Given the code:
Animal animal;
Cat kitty = new Cat();
BigCat big = new BigCat();
Tiger tig = new Tiger();
Tabby tab = new Tabby();
Will this code produce an error?
kitty = null;
- yesorrect!
- no
1 / 1 pts
Given a class Animal has a child Cat and a child BigCat. Cat has a child class Tabby and BigCat has a child class Tiger.
Given the code:
Animal animal;
Cat kitty = new Cat();
BigCat big = new BigCat();
Tiger tig = new Tiger();
Tabby tab = new Tabby();
Will this code produce an error?
animal = big;orrect!
- no
- yes
1 / 1 pts
Given a class Animal has a child Cat and a child BigCat. Cat has a child class Tabby and BigCat has a child class Tiger.
Given the code:
Animal animal;
Cat kitty = new Cat();
BigCat big = new BigCat();
Tiger tig = new Tiger();
Tabby tab = new Tabby();
Will this code produce an error?
big = tig;
- yesCorrect!
- no
1 / 1 pts
Given this code:
Animal myDog = new Dog(“Spot”);
myDog.speak();
What do we know about the Dog class and the Animal class?
- Animal is derived from Dogorrect!
- Dog is derived from Animal and Speak() is a method from the parent class that Dog over-rides
- We can tell nothing from this particular code. We don't see any definitions.
- Dog is actually an Interface for animal allowing an Animal to become a Dog.
1 / 1 pts
Given a class Animal has a child Cat and a child BigCat. Cat has a child class Tabby and BigCat has a child class Tiger.
Given the code:
Animal animal;
Cat kitty = new Cat();
BigCat big = new BigCat();
Tiger tig = new Tiger();
Tabby tab = new Tabby();
Will this code produce an error?
big = tab;
Correct!
- yes
- no
Expert Answer
Buy This Answer $15
-- OR --
Subscribe $20 / Month