AP Computer Science A Unit 9 Progress
Check: MCQ
Consider the following class declarations.public class Dog { private String name; public Dog() { name = "NoName"; } } public class Poodle extends Dog { private String size; public Poodle(String s) { size = s; } } The following statement appears in a method in another class.Poodle myDog = new Poodle("toy"); Which of the following best describes the result of executing the statement? Ans- B. The Poodle variable myDog is instantiated as a Poodle. The instance variable size is initialized to "toy". An implicit call to the no-argument Dog constructor is made, initializing the instance variable name to "NoName".Consider the following class declarations.public class Publication { private String title; public Publication() { title = "Generic"; } public Publication(String t) 1 / 2
{ title = t; } } public class Book extends Publication { public Book() { super(); } public Book(String t) { super(t); } } The following code segment appears in a method in another class.Book myBook = new Book("Adventure Story"); // Line 1 Book yourBook = new Book(); // Line 2 Which of the following best describes the result of executing the code segment? Ans- C.Object myBook is created using the one-argument Book constructor, which uses super to set myBook's title attribute to "Adventure Story". Object yourBook is created using super to call to the Publication no-argument constructor to set yourBook's title attribute to "Generic".Consider the following class declarations.public class Tree { private String treeVariety; public Tree() { treeVariety = "Oak"; } public Tree(String variety) { treeVariety = variety; } } public class DeciduousTree extends Tree { public DeciduousTree(String variety) {
- / 2