Questions# 101-120

Question 101)

Given the following code

class Base{}



public class MyCast extends Base{

static boolean b1=false;

static int i = -1;

static double d = 10.1;



public static void main(String argv[]){

        MyCast m = new MyCast();

        Base b = new Base();

	//Here

        }

}

Which of the following, if inserted at the comment //Here will allow the code to compile and run without error

1) b=m;
2) m=b;
3) d =i;
4) b1 =i;


Question 102)

Which of the following statements about threading are true

1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a method declared with the keyword synchronized
4) Thread scheduling algorithms are platform dependent


Question 103)

Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC.

The main difference between the two is that one runs the Linux operating System and the other runs the Windows System (of course another difference is that one needs constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?


1) Give the goahead for further design using the current scheme
2) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
3) Ask for the option of WindowsPC to be removed as it will soon be obsolete
4) Change the hierarchy to remove the need for the superfluous Computer Class.


Question 104)

Which of the following statements are true

1) An inner class may be defined as static
2) There are NO circumstances where an inner class may be defined as private
3) An anonymous class may have only one constructor
4) An inner class may extend another class


Question 105)

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

int Output=10;

boolean b1 = false;

if((b1==true) && ((Output+=10)==20)){

    System.out.println("We are equal "+Output);

    }else

    {

    System.out.println("Not equal! "+Output);

}

1) Compile error, attempting to peform binary comparison on logical data type
2) Compilation and output of "We are equal 10"
3) Compilation and output of "Not equal! 20"
4) Compilation and output of "Not equal! 10"


Question 106)

Given the following variables which of the following lines will compile without error?

String s = "Hello";

long l = 99;

double d = 1.11;

int i = 1;

int j = 0;
1) j= i <<s;

2) j= i<<j;

3) j=i<<d;

4)j=i<<l;

Question 107)

What will be output by the following line of code?

System.out.println(010|4);

1) 14
2) 0
3) 6
4) 12


Question 108)

Given the following variables

char c = 'c';

int i = 10;

double d = 10;

long l = 1;

String s = "Hello";

Which of the following will compile without error?

1)c=c+i;
2)s+=i;
3)i+=s;
4)c+=s;


Question 109)

Which of the following will compile without error?

1) File f = new File("/","autoexec.bat");
2) DataInputStream d = new DataInputStream(System.in);
3) OutputStreamWriter o = new OutputStreamWriter(System.out);
4) RandomAccessFile r = new RandomAccessFile("OutFile");


Question 110)

Given the folowing classes which of the following will compile without error?

interface IFace{}

class CFace implements IFace{}

class Base{}



public class ObRef extends Base{

public static void main(String argv[]){

        ObRef ob = new ObRef();

        Base b = new Base();

        Object o1 = new Object();

        IFace o2 = new CFace();

        }

}

1)o1=o2;

2)b=ob;

3)ob=b;

4)o1=b;

Question 111)

Given the following code what will be the output?

class ValHold{

        public int i = 10;

}

public class ObParm{

public static void main(String argv[]){

        ObParm o = new ObParm();

        o.amethod();

        }

        public void amethod(){

                int i = 99;

                ValHold v = new ValHold();

                v.i=30;

                another(v,i);

                System.out.println(v.i);



        }//End of amethod



        public void another(ValHold v, int i){

                i=0;

                v.i = 20;

                ValHold vh = new ValHold();

                v =  vh;

                System.out.println(v.i+ " "+i);

        }//End of another

}

1) 10,0, 30
2) 20,0,30
3) 20,99,30
4) 10,0,20



Question 112)

Given the following class definition, which of the following methods could be legally placed after the comment

//Here 
public class Rid{

        public void amethod(int i, String s){}

	//Here

}

1)public void amethod(String s, int i){}
2)public int amethod(int i, String s){}
3)public void amethod(int i, String mystring){}
4) public void Amethod(int i, String s) {}


Question 113)

Given the following class definition which of the following can be legally placed after the comment line
//Here ?

class Base{

public Base(int i){}

}



public class MyOver extends Base{

public static void main(String arg[]){

                MyOver m = new MyOver(10);

                }

        MyOver(int i){

                super(i);

        }

        MyOver(String s, int i){

                this(i);

				 //Here

               

        }

}

1)MyOver m = new MyOver();
2)super();
3)this("Hello",10);
4)Base b = new Base(10);


Question 114)

Given the following class definition, which of the following statements would be legal after the comment //Here

class InOut{

String s= new String("Between");





        public void amethod(final int iArgs){

        int iam;

               class Bicycle{

                        public void sayHello(){

						//Here

                        }//End of bicycle class

                }

        }//End of amethod

       public void another(){

       int iOther;

       }

}

1)System.out.println(s);
2) System.out.println(iOther);
3) System.out.println(iam);
4) System.out.println(iArgs);


Question 115)

Which of the following are methods of the Thread class?

1) yield()
2) sleep(long msec)
3) go()
4) stop()


Question 116)

Which of the following methods are members of the Vector class and allow you to input a new element

1) addElement
2) insert
3) append
4) addItem


Question 117)

Which of the following statements are true?

1) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.
2) Under no circumstances can a class be defined with the private modifier
3) A inner class may under some circumstances be defined with the protected modifier
4) An interface cannot be instantiated


Question 118)

Which of the following are correct event handling methods


1) mousePressed(MouseEvent e){}
2) MousePressed(MouseClick e){}
3) functionKey(KeyPress k){}
4) componentAdded(ContainerEvent e){}


Question 119)

Which of the following are methods of the Collection interface?
1) iterator
2) isEmpty
3) toArray
4) setText


Question 120)

Which of the following best describes the use of the synhronized keyword?

1) Allows two process to run in paralell but to communicate with each other
2) Ensures only one thread at a time may access a method or object
3) Ensures that two or more processes will start and end at the same time
4) Ensures that two or more Threads will start and end at the same time


Back   Answers   Next      Index   Home