• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Question - Inheritance

 
Mukti Bajaj
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Q)You are designing an application to recommend dog breeds to potential pet owners. To maximize the advantage of working in an object-oriented language, you have created a Dog class, which will be extended by classes representing different kinds of dogs. The following code fragment shows the class declaration and all of the instance variables in the Dog class: 1. public class Dog extends Object { 2. float avgWeight; 3. float avgLifespan; 4. String breedName; Which of the following would be reasonable variable declarations for the SportingDog class, which extends Dog? [Check all correct answers]
A) private float avgWeight ;
B) private Dog theDog ;
C) String[] hunts ;
D) String breedName ;
Answer Given : C
What can be the possible answer??
Mukti
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mukti
a. FALSE - field already exists in superclass
b. FALSE - same as above
c. TRUE - new field to hold an array of what the sporting dog
hunts
d. FALSE - field already exists in the superclass
A subclass is a specialization of the it's superclass; it reasonable to add new fields.
Hope that helps
------------------
Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic