Have a Question ?

Home / Answered Questions / CSE205 / cse205-quiz-5-inheritance-and-polymorphism-q-289

(Solved): CSE205 Quiz 5: Inheritance and Polymorphism ...


CSE205

Quiz 5: Inheritance and Polymorphism 

 

Question 1

1 / 1 pts

T/F? - Private properties are not inherited into a child class.ou Answered

  •   True
  •   False

Question 2

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

Question 3

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.

Question 4

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 

Question 5

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

Question 6

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

Question 7

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 

Question 8

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

Question 9

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

Question 10

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.

 

Question 11

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

 

 



We have an Answer from Expert View Expert Answer

Expert Answer


We have an Answer from Expert
Buy This Answer $15

-- OR --

Subscribe To View Unlimited Answers
Subscribe $20 / Month