SCJP Quiz
  Page #7
 
Topic: Declarations and access control
Question #61

What will be the result when you attempt to compile this program?
public class Rand
{
    public static void main(String argv[])
    {
        int iRand;
        iRand = Math.random();
        System.out.println(iRand);
    }
}
  1. Compile time error referring to a cast problem
  2. A random number between 1 and 10
  3. A random number between 0 and 1
  4. A compile time error about random being an unrecognised method
Click here to see the answer
Click here to see explanation

Question #62

Given the following code, What code would be most likely for the body of the ioCall method
  1. public void ioCall ()throws IOException{ DataInputStream din = new DataInputStream(System.in); din.readChar();
  2. public void ioCall ()throw IOException{ DataInputStream din = new DataInputStream(System.in); din.readChar();
  3. public void ioCall (){ DataInputStream din = new DataInputStream(System.in); din.readChar(); }
  4. public void ioCall throws IOException(){ DataInputStream din = new DataInputStream(System.in); din.readChar(); }
Click here to see the answer
Click here to see explanation

Question #63

What will happen when you compile and run the following code?
public class Scope
{
    private int i;
    public static void main(String argv[])
    {
        Scope s = new Scope();
        s.amethod();
    }//End of main
    public static void amethod()
    {
        System.out.println(i);
    }//end of amethod
}//End of class
  1. A value of 0 will be printed out
  2. Nothing will be printed out
  3. A compile time error
  4. A compile time error complaining of the scope of the variable i
Click here to see the answer
Click here to see explanation

Question #64

Which of the following can you perform using the File class?
  1. Change the current directory
  2. Return the name of the parent directory
  3. Delete a file
  4. Find if a file contains text or binary information
Click here to see the answer
Click here to see explanation

Question #65

Which statement is true of the following code?
public class Rpcraven
{
    public static void main(String argv[])
    {
        Pmcraven pm1 = new Pmcraven("One");
        pm1.run();
        Pmcraven pm2 = new Pmcraven("Two");
       pm2.run();

    }
}

class Pmcraven extends Thread
{
    private String sTname="";
    Pmcraven(String s)
    {
        sTname = s;
    }
    public void run()
    {
        for(int i =0; i < 2 ; i++)
        {
            try
            {
                sleep(1000);
            }
            catch(InterruptedException e){}
            yield();
            System.out.println(sTname);
        }
    }
}
  1. Compile time error, class Rpcraven does not import java.lang.Thread
  2. Output of One One Two Two
  3. Output of One Two One Two
  4. Compilation but no output at runtime
Click here to see the answer
Click here to see explanation

Question #66

You want to ensure that the Java Virtual Machine will run its garbage collection just before you start a complex routine. What can you do to be certain that garbage collection will run when you want .
  1. You cannot be certain when garbage collection will run
  2. Use the Runtime.gc() method to force garbage collection
  3. Ensure that all the variables you require to be garbage collected are set to null
  4. Use the System.gc() method to force garbage collection
Click here to see the answer
Click here to see explanation

Question #67

Which of the following most closely describes a bitset collection?
  1. A class that contains groups of unique sequences of bits
  2. A method for flipping individual bits in instance of a primitive type
  3. An array of boolean primitives that indicate zeros or ones
  4. A collection for storing bits as on-off information, like a vector of bits
Click here to see the answer
Click here to see explanation

Question #68

You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java
//Base.java
package Base;
class Base
{
    protected void amethod()
    {
        System.out.println("amethod");
    }//End of amethod
}//End of class base
package Class1;
//Class1.java
public class Class1 extends Base
{
    public static void main(String argv[])
    {
        Base b = new Base();
        b.amethod();
    }//End of main
}//End of Class1
  1. Compile Error: Methods in Base not found
  2. Compile Error: Unable to access protected method in base class
  3. Compilation followed by the output "amethod"
  4. Compile error: Superclass Class1.Base of class Class1.Class1 not found
Click here to see the answer
Click here to see explanation

Question #69

What will happen when you attempt to compile and run the following code?
class Base
{
    private void amethod(int iBase)
    {
        System.out.println("Base.amethod");
    }
}

class Over extends Base
{
    public static void main(String argv[])
    {
        Over o = new Over();
        int iBase=0;
        o.amethod(iBase);
    }

    public void amethod(int iOver)
    {
        System.out.println("Over.amethod");
    }
}
  1. Compile time error complaining that Base.amethod is private
  2. Runtime error complaining that Base.amethod is private
  3. Output of "Base.amethod"
  4. Output of "Over.amethod"
Click here to see the answer
Click here to see explanation

Question #70

The following code will print
if( new Boolean("true") == new Boolean("true"))
    System.out.println("True");
else
    System.out.println("False");
  1. Compilation error.
  2. No compilation error, but runtime exception.
  3. Prints "True".
  4. Prints "False".
Click here to see the answer
Click here to see explanation

 
  Today, there have been 1 visitors (1 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