Name: 
 

Interfaces and Abstract Classes Review



Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 1. 

A class that implements   Comparable   has to at least have how many methods?

public interface Comparable
{
   public abstract int compareTo();
}

a.
0
b.
1
c.
2
d.
3
e.
4
 

 2. 

A class that implements   Locatable   has to at least have how many methods?

public interface Locatable
{
   int getX();
   int getY();
   double getSpeed();
}

a.
0
b.
1
c.
2
d.
3
e.
4
 

 3. 

All methods located inside of an interface are automatically set with what access?
a.
public
b.
private
c.
protected
d.
A and B only
e.
A, B, and C
 

 4. 

All methods located inside of an interface are automatically labeled with which of the following modifiers?
a.
static
b.
abstract
c.
final
d.
protected
e.
interface
 

 5. 

Which of the following could fill <blank 1>?

public interface Testable
{
  
<blank 1>
}

a.
double getScore();
b.
public double getScore();
c.
public abstract double getScore();
d.
A and B only
e.
A, B, and C
 

 6. 

Which of the following could not fill <blank 1>?

public interface Testable
{
  
<blank 1>
}
a.
private void setScore(double s);
b.
void setScore(double s);
c.
abstract void setScore(double s);
d.
A and B only
e.
A, B, and C
 

 7. 

Assuming <blank 1> is filled correctly, which of the following could fill <blank 2>?

public interface Locatable
{
   int getX();
   public abstract int getY();
   double getSpeed();
}

public class Ship implements Locatable
{
   private int xPos, yPos;
   private double speed;

  
<blank 1>  Ship()
   { 
      //code not shown 
   }

   public Ship(int x, int y, double s)
   { 
      xPos=x;
      yPos=y;
      speed=s;
   }

  
<blank 2>  int getX()
   {
      return xPos;
   }

  
<blank 2> int getY()
   {
      return yPos;
   }

  
<blank 2> double getSpeed()
   {
      return speed;
   }
}

//code in the main method of another class
<blank 3>
a.
public
b.
protected
c.
private
d.
abstract
e.
A, B, and C
 

 8. 

Assuming <blank 1> is filled correctly, which of the following could fill <blank 3>?

public interface Locatable
{
   int getX();
   public abstract int getY();
   double getSpeed();
}

public class Ship implements Locatable
{
   private int xPos, yPos;
   private double speed;

  
<blank 1>  Ship()
   { 
      //code not shown 
   }

   public Ship(int x, int y, double s)
   { 
      xPos=x;
      yPos=y;
      speed=s;
   }

  
<blank 2>  int getX()
   {
      return xPos;
   }

  
<blank 2> int getY()
   {
      return yPos;
   }

  
<blank 2> double getSpeed()
   {
      return speed;
   }
}

//code in the main method of another class
<blank 3>
a.
Locatable x = new Locatable();
b.
Ship w = new Ship(3,5);
c.
Locatable s = new Ship(3,5,7.8);
d.
Ship w = new Locatable(3,5,7.8);
e.
Locatable s = new Ship(3.5,5,7);
 

 9. 

A class can extend another   _________________ .
a.
abstract class
b.
class
c.
interface
d.
A and B
e.
A, B, and C
 

 10. 

A abstract class can extend another   _________________ .
a.
abstract class
b.
class
c.
interface
d.
A and B
e.
A, B, and C
 

 11. 

public class X   __________________  Y _____________________ A, B, C
a.
extends  implements
b.
extends extends
c.
implements extends
d.
implements implements
e.
A and B only
 

 12. 

A class can extend how many other classes?
a.
0
b.
1
c.
2
d.
as many as you want
e.
A and D only
 

 13. 

A class can implement how many other interfaces?
a.
0
b.
1
c.
2
d.
as many as you want
e.
A and D only
 

 14. 

What is the minimum number of methods a class extending abstract class Demo could have?

public abstract class Demo
{
   public abstract String destroy();
}
a.
0
b.
1
c.
2
d.
3
e.
4
 

 15. 

What is the minimum number of methods a class extending abstract class Demo could have?

public abstract class Demo
{
   public Demo()
   {  
   }

   public abstract String destroy();

   public String toString()
   {
      return "--";
   }
}

a.
0
b.
1
c.
2
d.
3
e.
4
 

 16. 

Which of the following could fill <blank 1>?

public abstract class APlayer
{
   private ArrayList<String> stuff;
   private int scnt;

   public APlayer()
   { 
            //code not shown 
   }  

   public APlayer(String stuff, int count)
   { 
            //code not shown 
   }

   public int getStuffCount()
   {
      return scnt;
   }

   public
<blank 1> void play();
}

public class Player extends APlayer
{
   public Player()
   {
      super();
   }

   public Player(String s, int c)
   {
     
<blank 2>
   }

   public void play()
   {
             //code not shown
   }
}

public class ThePlayer extends APlayer
{
   public ThePlayer()
   {
   }
   public void play()
   {
           //code not shown
   }
}

//code in the main method of another class
<blank 3>   //define a variable
<blank 4>       //call methods on the variable
a.
final
b.
static
c.
protected
d.
abstract
e.
C and D
 

 17. 

Assuming <blank 1> is filled correctly, which of the following could fill <blank 2> to make a call the parent two parameter constructor?

public abstract class APlayer
{
   private ArrayList<String> stuff;
   private int scnt;

   public APlayer()
   { 
            //code not shown 
   }  

   public APlayer(String stuff, int count)
   { 
            //code not shown 
   }

   public int getStuffCount()
   {
      return scnt;
   }

   public
<blank 1> void play();
}

public class Player extends APlayer
{
   public Player()
   {
      super();
   }

   public Player(String s, int c)
   {
     
<blank 2>
   }

   public void play()
   {
             //code not shown
   }
}

public class ThePlayer extends APlayer
{
   public ThePlayer()
   {
   }
   public void play()
   {
           //code not shown
   }
}

//code in the main method of another class
<blank 3>    //make a variable
<blank 4>          //call a method on the variable
a.
super(s,c);
b.
super("34234",7);
c.
super(s);
d.
super(7,44);
e.
A and B
 

 18. 

Assuming <blank 1>  and <blank 2> are filled correctly, which of the following could fill <blank 3>?

public abstract class APlayer
{
   private ArrayList<String> stuff;
   private int scnt;

   public APlayer()
   { 
            //code not shown 
   }  

   public APlayer(String stuff, int count)
   { 
            //code not shown 
   }

   public int getStuffCount()
   {
      return scnt;
   }

   public
<blank 1> void play();
}

public class Player extends APlayer
{
   public Player()
   {
      super();
   }

   public Player(String s, int c)
   {
    
<blank 2>
   }

   public void play()
   {
             //code not shown
   }
}

public class ThePlayer extends APlayer
{
   public ThePlayer()
   {
   }
   public void play()
   {
           //code not shown
   }
}

//code in the main method of another class
<blank 3>   //make a variable
<blank 4>       //call a method on the variable

a.
APlayer x = new APlayer();
b.
APlayer x = new Player("34234",7);
c.
APlayer x = new APlayer("34234",7);
d.
APlayer x = new ThePlayer("34234");
e.
more than one of these
 

 19. 

Assuming <blank 1>, <blank 2>, and <blank 3> has been filled correctly, which of the following could fill <blank 4>?

public abstract class APlayer
{
   private ArrayList<String> stuff;
   private int scnt;

   public APlayer()
   { 
            //code not shown 
   }  

   public APlayer(String stuff, int count)
   { 
            //code not shown 
   }

   public int getStuffCount()
   {
      return scnt;
   }

   public
<blank 1> void play();
}

public class Player extends APlayer
{
   public Player()
   {
      super();
   }

   public Player(String s, int c)
   {
     
<blank 2>
   }

   public void play()
   {
             //code not shown
   }
}

public class ThePlayer extends APlayer
{
   public ThePlayer()
   {
   }
   public void play()
   {
           //code not shown
   }
}

//code in the main method of another class
<blank 3>    //define a variable
<blank 4>         //call methods on that variable

a.
x.play();
b.
x.getStuffCount();
c.
x.scnt;
d.
A and B only
e.
A,B, and C
 

 20. 

What is the signature for the Ford class so that it will be forced to implement the Car interface?
a.
public class Ford extends Car
d.
public class Ford finalizes Car
b.
public class Ford inherits Car
e.
None of these
c.
public class Ford uses Car
 

 21. 

The property of two methods having the same name but with possibly different implementations (in different classes) is known as which of the following?
a.
similarity
d.
overriding
b.
polymorphism
e.
None of these
c.
inheritance
 

 22. 

Suppose that the class Bank implements the two interfaces Accounting and Personnel. It also inherits the class Financial. Write the signature for the Bank class.
a.
public class Bank extends Accounting, Personnel implements Financial
b.
public class Bank implements Accounting, Personnel extends Financial
c.
public class Bank extends Financial implements Accounting, Personnel
d.
None of these
 

 23. 

Write the code for an interface called Trigonometry that has a method called sin that both receives and returns a double. It has another method called convertToRadians that takes an integer parameter. It returns a double.
a.
public interface Trigonometry
{
       double sin(double theta){  }             
       double convertToRadians(int degrees){  }
}
b.
public interface Trigonometry
{
       double sin(double theta);             
       double convertToRadians(int degrees);
}
c.
public interface Trigonometry
{
       double sin(double theta)             
       double convertToRadians(int degrees)
}
d.
public interface Trigonometry
{
       int sin(double theta);             
       int convertToRadians(double degrees);
}
e.
None of these
 

 24. 

Which is the proper way to instantiate a List object that is implemented as an ArrayList?
a.
List lst = ArrayList( );
d.
More than one of these
b.
List lst = new ArrayList( );
e.
None of these
c.
ArrayList lst = new ArrayList( );
 

 25. 

What is the only method of the Comparable interface?
a.
Compare
d.
compare
b.
CompareTo
e.
None of these
c.
compareTo
 

 26. 

What is printed by the following code?

Integer iw = new Integer(108); //Java 5.0, Integer iw = 108;
Integer ij = new Integer(92); //Java 5.0, Integer ij = 92;
int i = iw.compareTo(ij);
System.out.println(i);
a.
positive number
c.
zero
b.
negative number
 



 
Check Your Work     Start Over