Questions# 81-100

Question 81)

How does the set collection deal with duplicate elements?

1) An exception is thrown if you attempt to add an element with a duplicate value
2) The add method returns false if you attempt to add an element with a duplicate value
3) A set may contain elements that return duplicate values from a call to the equals method
4) Duplicate values will cause an error at compile time


Question 82)

What can cause a thread to stop executing?

1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread's stop method.
4) A call to the halt method of the Thread class


Question 83)

For a class defined inside a method, what rule governs access to the variables of the enclosing method?

1) The class can access any variable
2) The class can only access static variables
3) The class can only access transient variables
4) The class can only access final variables


Question 84)


Under what circumstances might you use the yield method of the Thread class

1) To call from the currently running thread to allow another thread of the same or higher priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter designating which thread should be allowed to run


Question 85)

What will happen when you attempt to compile and run the following code

public class Hope{

public static void main(String argv[]){

 Hope h = new Hope();

 }

protected Hope(){

 for(int i =0; i <10; i ++){

  System.out.println(i);

  }

 }

}

1) Compilation error: Constructors cannot be declared protected
2) Run time error: Constructors cannot be declared protected
3) Compilation and running with output 0 to 10
4) Compilation and running with output 0 to 9


Question 86)

What will happen when you attempt to compile and run the following code

public class MySwitch{



public static void main(String argv[]){

    MySwitch ms= new MySwitch();

    ms.amethod();

    }



public void amethod(){



    int k=10; 

        switch(k){ 

        default: //Put the default at the bottom, not here

            System.out.println("This is the default output"); 

            break; 

         case 10: 

            System.out.println("ten");

         case 20: 

            System.out.println("twenty"); 

        break; 

       }

    }

}

1) None of these options
2) Compile time error target of switch must be an integral type
3) Compile and run with output "This is the default output"
4) Compile and run with output of the single line "ten"


Question 87)

Which of the following is the correct syntax for suggesting that the JVM performs garbage collection

1) System.free();
2) System.setGarbageCollection();
3) System.out.gc();
4) System.gc();


Question 88)


What will happen when you attempt to compile and run the following code

public class As{

int i = 10;

int j;

char z= 1;

boolean b;

public static void main(String argv[]){

                As a = new As();

                a.amethod();

        }

        public void amethod(){

        System.out.println(j);

        System.out.println(b);                

        }

}

1) Compilation succeeds and at run time an output of 0 and false
2) Compilation succeeds and at run time an output of 0 and true
3) Compile time error b is not initialised
4) Compile time error z must be assigned a char value


Question 89)


What will happen when you attempt to compile and run the following code with the command line "hello there"

public class Arg{

String[] MyArg;

        public static void main(String argv[]){

        MyArg=argv;

        }

        public void amethod(){

                System.out.println(argv[1]);

        }

}

1) Compile time error
2) Compilation and output of "hello"
3) Compilation and output of "there"
4) None of the above


Question 90)

What will happen when you attempt to compile and run the following code

public class StrEq{



public static void main(String argv[]){

        StrEq s = new StrEq();

        }

        private StrEq(){

                String s = "Marcus";

                String s2 = new String("Marcus");

                if(s == s2){

                        System.out.println("we have a match");

                        }else{

                        System.out.println("Not equal");

                }

       }

}

1) Compile time error caused by private constructor
2) Output of "we have a match"
3) Output of "Not equal"
4) Compile time error by attempting to compare strings using ==


Question 91)

1) What will happen when you attempt to compile and run the following code

import java.io.*;



class Base{

public static void amethod()throws FileNotFoundException{}

}



public class ExcepDemo extends Base{

public static void main(String argv[]){

       ExcepDemo e = new ExcepDemo();

}

public static void amethod(){}



protected ExcepDemo(){

 try{

  DataInputStream din = new DataInputStream(System.in);

  System.out.println("Pausing");

  din.readChar();

  System.out.println("Continuing");

  this.amethod();

  }catch(IOException ioe) {}

}



}

1)Compile time error caused by protected constructor
2) Compile time error caused by amethod not declaring Exception
3) Runtime error caused by amethod not declaring Exception
4) Compile and run with output of "Pausing" and "Continuing" after a key is hit


Question 92)


What will happen when you attempt to compile and run this program

public class Outer{

public String name = "Outer";

public static void main(String argv[]){

        Inner i = new Inner();

        i.showName();

    }//End of main



        private class Inner{

        String name =new String("Inner");

                void showName(){

                        System.out.println(name);

                }

        }//End of Inner class



}

1) Compile and run with output of "Outer"
2) Compile and run with output of "Inner"
3) Compile time error because Inner is declared as private
4) Compile time error because of the line creating the instance of Inner


Question 93)

What will happen when you attempt to compile and run this code

//Demonstration of event handling

import java.awt.event.*;

import java.awt.*;



public class MyWc extends Frame implements WindowListener{

public static void main(String argv[]){

        MyWc mwc = new MyWc();

        }

        public void windowClosing(WindowEvent we){

                System.exit(0);

                }//End of windowClosing



      public void  MyWc(){

        setSize(300,300);

        setVisible(true);

        }

}//End of class

1) Error at compile time
2) Visible Frame created that that can be closed
3) Compilation but no output at run time
4) Error at compile time because of comment before import statements


Question 94)

Which option most fully describes will happen when you attempt to compile and run the following code

public class MyAr{

public static void main(String argv[]) {

        MyAr m = new MyAr();

        m.amethod();

        }

        public void amethod(){

        static int i;

        System.out.println(i);

        }

}

1) Compilation and output of the value 0
2) Compile time error because i has not been initialized
3) Compilation and output of null
4) Compile time error


Question 95)

Which of the following will compile correctly

1) short myshort = 99S;
2) String name = 'Excellent tutorial Mr Green';
3) char c = 17c;
4)int z = 015;


Question 96)

Which of the following are Java key words
1)double
2)Switch
3)then
4)instanceof


Question 97)

What will be output by the following line?

System.out.println(Math.floor(-2.1));

1) -2
2) 2.0
3) -3
4) -3.0


Question 98)

Given the following main method in a class called Cycle and a command line of

java Cycle one two

what will be output?

public static void main(String bicycle[]){

	System.out.println(bicycle[0]);

}

1) None of these options
2) cycle
3) one
4) two


Question 99)

Which of the following statements are true?

1) At the root of the collection hierarchy is a class called Collection
2) The collection interface contains a method called enumerator
3) The interator method returns an instance of the Vector class
4) The set interface is designed for unique elements


Question 100)

Which of the following statements are correct?

1) If multiple listeners are added to a component only events for the last listener added will be processed
2) If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
3) Adding multiple listeners to a comnponent will cause a compile time error
4) You may remove as well add listeners to a component.


Back   Answers   Next      Index   Home