Loading
notes intro/old submit AP Problems the dump links
 

Quiz Polymorphism

 

id:

 

 

1.True or false: Polymorphism works with classes (abstract or regular) and interfaces true false

For the following examples:

public class Book
{
    public Book()
   {
     // implementation not shown
   }
}

public class Dictionary extends Book
{
   public Dictionary(int definitions)
   {
       //implementation not shown
   }
}
	    

2. Which of the following is correct?

Book b=new Dictionary(5200); Dictionary d=new Book();

 

3.In the example from class, if we declared staffList to be an array of StaffMembers and filled it as the example from class and staffList[0] is an executive. If we say: staffList[0].pay() would call

pay that belongs to staffMember

pay that belongs to executive

you need to cast it as an executive to use pay

 

4. Again above, but we try to say: staffList[0].bonus(300)

bonus that belongs to staffMember

bonus that belongs to executive

you get a run-time error (you should have cast it as an executive to use bonus).

you get a compile time error (you should have cast it as an executive to use bonus).

 

5. A big benefit of using polymorphism is:

it allows elegant object oriented design

it allows you to put different objects in one data structure

it allows methods to take in different objects so they are more useful

all of the above