SCJP Quiz
  Page #1
 
Topic: Declarations and access control
Question #1

Which of the following statements are true?
  1. A constructor may not be declared as private
  2. A Constructor with no arguments will be the default constructor
  3. Constructors cannot be overloaded
  4. A call to a constructor in a parent class can only be made from within a constructor.
Click here to see the answer
Click here to see explanation

Question #2

What will happen when you attempt to compile and run the following code?
public class Mickle
{
   public static void main(String argv[])
  {
    new Mickle();
  }
  public Mickle()
  {
    String s[][] = new String[2][2];
    System.out.println(s[1][1]);
    System.out.println(s[1][2]);
  }
}
  1. Compile time error
  2. Compilation and output of two blanks (with carriage returns)
  3. Compilation and output of null followed by ArrayIndexOutOfBoundsException
  4. Compilation and output of blanke followed by ArrayIndexOutOfBoundsException
Click here to see the answer
Click here to see explanation

Question #3

Which of the following statements are true?
  1. The abstract modifier may be applied to classes, methods and primitives
  2. The abstract modifier may be applied to classes but not methods
  3. A non abstract class that extends an abstract class must implement all the abstract methods of the inherited class
  4. The abstract modifier may be applied to both classes and methods
Click here to see the answer
Click here to see explanation

Question #4

What will happen when you attempt to compile and run the following code?
interface Skeleton
{
   public char getSize(int iSize);
}


public class Huskisson implements Skeleton
{
   int iSize=99;
   public static void main(String argv[])
   {
      new Huskisson();
   }
   Huskisson()
   {
      int iSize=1;
      System.out.println(getSize(iSize));
   }

   public int getSize(int iSize)
   {
      return iSize;
   }
}
  1. Compilation and output of 1
  2. Compile time error
  3. Compilation and output of 99
  4. Compilation but runtime error
Click here to see the answer
Click here to see explanation

Question #5

What will happen when you attempt to compile and run the following code?
class Vict
{
   private Vict()
   {
      System.out.print("Vict");
   }
}

public class BLBeck extends Vict
{
   public static void main(String argv[])
   {
      new BLBeck();
   }

   BLBeck()
   {
      System.out.print("BLBeck");
   }
}
  1. Compilation and output of "BLBeck"
  2. Compilation and output of "BLBeckVict"
  3. Compilation and output of "VictBLBeck"
  4. Compile time error
Click here to see the answer
Click here to see explanation

Question #6

What will happen when you attempt to compile and run the following code?
abstract class Town
{
   private String sDialingCode;
   public String getDialingCode()
   {
      return sDialingCode;
   }
   public void setDialingCode(String sDialingCode)
   {
      this.sDialingCode=sDialingCode;
   }
   abstract String getCounty();
}

public class Felpersham extends Town
{
   public static void main(String argv[])
   {
      new Felpersham();
   }
   Felpersham()
   {
       setDialingCode("01905");
   }
}
  1. Compile time error because Felphersham does not implement getCounty method.
  2. Compilation and no output at runtime
  3. Compilation but runtime exception
  4. Compile time error, an abstract class cannot have non abstract methods
  5. Compile time error, an abstract class has no 'this' instance
Click here to see the answer
Click here to see explanation

Question #7

Which of the following statements are true of a method local inner class?
  1. It has access to all members of its enclosing class
  2. It can only access final variables of its enclosing method
  3. It can be marked as static
  4. It can only access final members of its enclosing class
Click here to see the answer
Click here to see explanation

Question #8

Given the following class definition
public class ShrubHill
{
   public void foregate(String sName){}
   //Here
}
Which of the following methods could be legally placed immediately after the comment //Here
  1. public int foregate(String sName){}
  2. public void foregate(StringBuffer sName){}
  3. public void foreGate(String sName){}
  4. private void foregate(String sType){}
Click here to see the answer
Click here to see explanation

Question #9

Which of the following can legally be inserted into an interface?
  1. public static String getPostCode();
  2. public abstract String getName();
  3. private String getAverageHousePrice();
  4. public void setPostCode(String s) { System.out.print(s); }
Click here to see the answer
Click here to see explanation

Question #10

What will happen when you attempt to compile and run the following code?
public class Wolfe
{
   public static void main(String argv[])
   {
      Wolfe w = new Wolfe();
      w.Go();
   }
   public void Go()
   {
      Account personal = new Account();
      personal.rate=7;
      Account business = new Account();
      business.rate =5;
      deduct(business);
      System.out.println(business.balance);
      System.out.println(personal.rate);
   }
   public void deduct(Account a)
   {
      a.balance=200;
   }
}
class Account
{
   static int rate;
   public int balance=100;
}
  1. Compile time error, variable rate in class Account is not initialized
  2. Output of 200 and 7
  3. Output of 100 and 5
  4. Output of 200 and 5
Click here to see the answer
Click here to see explanation
 
  Today, there have been 7 visitors (9 hits) on this page!  
 
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free