SCJP Quiz
  Page #2
 
Topic: Declarations and access control
Question #11

Which of the following statements are true?
  1. An array may contain only primitives not objects
  2. An array may contain primitives or objects
  3. The elements of an array may themselves be arrays
  4. Arrays have a size method that returns the number of elements
Click here to see the answer
Click here to see explanation

Question #12

Given the following code, which of the options if inserted on the line after the comment //here will allow the code to compile without error?
class Wchapel
{
   String sDescription = "Aldgate";
   public String getDescription()
   {
      return "Mile End";
   }
   public void output(int i )
   {
      System.out.println(i);
   }
}

interface Liz
{

}

public class Wfowl extends Wchapel implements Liz
{
   private int i = 99;
   public static void main(String argv[])
   {
      Wfowl wf = new Wfowl();
      wf.go();
   }
   public void go()
   {
      //here
   }
}
  1. super().output(100);
  2. new Wfowl().output(i);
  3. class test implements Liz{}
  4. System.out.println(sDescription);
  5. new Wfowl();
  6. getDescription();
Click here to see the answer
Click here to see explanation

Question #13

Given the following code, which of the options if inserted on the line after the comment //here will allow the code to compile without error?
public class Kirving
{
   private final int i = 10;
   public static void main(String argv[])
   {
      Kirving ki = new Kirving();
      ki.go(3);
   }
   public void go(int z)
   {
      //here
   }
}
  1. int i = z;
  2. class test{ int j = i; }
  3. int j = i;
  4. i++;
Click here to see the answer
Click here to see explanation

Question #14

Which of the following lines will compile without warning or error?
  1. float f=1.3;
  2. char c="a";
  3. byte b=257;
  4. boolean b=null;
  5. int i=10;
Click here to see the answer
Click here to see explanation

Question #15

What will happen if you try to compile and run the following code?
public class MyClass
{
      public static void main(String arguments[])
      {
            amethod(arguments);
      }
      public void amethod(String[] arguments)
      {
            System.out.println(arguments);
            System.out.println(arguments[1]);
      }
}
  1. Error: Can't make static reference to void amethod.
  2. Error: method main not correct
  3. Error: array must include parameter
  4. amethod must be declared with String
Click here to see the answer
Click here to see explanation

Question #16

Which of the following will compile without error?

  1. import java.awt.*;
    package Mypackage;
    class Myclass {}

  2. package MyPackage;
    import java.awt.*;
    class MyClass{}

  3. /*This is a comment */
    package MyPackage;
    import java.awt.*;
    class MyClass{}
Click here to see the answer
Click here to see explanation

Question #17

A byte can be of what size?
  1. -128 to 127
  2. (-2 power 8 )-1 to 2 power 8
  3. -255 to 256
  4. Depends on the particular implementation of the Java Virtual machine
Click here to see the answer
Click here to see explanation

Question #18

What will be printed out if this code is run with the following command line?
java myprog good morning
public class myprog
{
   public static void main(String argv[])
   {
      System.out.println(argv[2]);
   }
}
  1. myprog
  2. good
  3. morning
  4. Exception: java.lang.ArrayIndexOutOfBoundsException
Click here to see the answer
Click here to see explanation

Question #19

Which of the following is NOT a keyword or reserved word in Java?
  1. if
  2. then
  3. goto
  4. while
  5. case
Click here to see the answer
Click here to see explanation

Question #20

Which of the following are legal identifiers?
  1. 2variable
  2. variable2
  3. _whatavariable
  4. _3_
  5. $anothervar
  6. #myvar
Click here to see the answer
Click here to see explanation
 
  Today, there have been 6 visitors (8 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