Java Paper
Java Paper
Java Test
Question 1:
What will happen when you attempt to compile and run this code?
1) The code will compile and run, printing out the words "My Func"
2) The compiler will complain that the Base class has non abstract methods
3) The code will compile but complain at run time that the Base class has non abstract
methods
4) The compiler will complain that the method myfunc in the base class has no body,
nobody at all to looove it
Question 2:
What will happen when you attempt to compile and run this code?
1) The compiler will complain that main is a reserved word and cannot be used for a class
2) The code will compile and when run will print out "Hello cruel world"
3) The code will compile but will complain at run time that no constructor is defined
4) The code will compile but will complain at run time that main is not correctly defined
Question 3:
1) public
2) private
3) friendly
4) transient
5) vagrant
Question 4:
What will happen when you attempt to compile and run this code?
class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
1) The code will compile and run, printing out the words "My Func"
2) The compiler will complain that the Base class is not declared as abstract.
3) The code will compile but complain at run time that the Base class has non abstract
methods
4) The compiler will complain that the method myfunc in the base class has no body,
nobody at all to looove it
Question 5:
Question 6:
What will happen when you attempt to compile and run this code?
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
1) Compile time error indicating that a class with any final methods must be declared
final itself
2) Compile time error indicating that you cannot inherit from a class with final methods
3) Run time error indicating that Base is not defined as final
4) Success in compilation and output of "amethod" at run time.
Question 7:
What will happen when you attempt to compile and run this code?
amethod available
4) Compilation and execution without error
Question 8:
What will happen when you attempt to compile and run this code?
Question 9:
What happens when you attempt to compile and run these two files in the same
directory?
//File P1.java
package MyPackage;
class P1{
void afancymethod(){
//File P2.java
afancymethod();
Question 10:
You want to find out the value of the last element of an array. You write the following
code. What will happen when you compile and run it.?
Question 11:
You want to loop through an array and stop when you come to the last element. Being a
good java programmer and forgetting everything you ever knew about C/C++ you know
that arrays contain information about their size. Which of the following can you use?
1)myarray.length();
2)myarray.length;
3)myarray.size
4)myarray.size();
Question 12:
What best describes the appearance of an application with the following code?
import java.awt.*;
public class FlowAp extends Frame{
public static void main(String argv[]){
FlowAp fa=new FlowAp();
fa.setSize(400,300);
fa.setVisible(true);
FlowAp(){
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"));
add(new Button("Four"));
}//End of constructor
}//End of Application
Question 13:
1) North, South,East,West
2) Assign a row/column grid reference
3) Pass a X/Y percentage parameter to the add method
4) Do nothing, the FlowLayout will position the component
Question 14:
Question 15:
1) ipadx
2) fill
3) insets
4) width
Question 16:
What most closely matches the appearance when this code runs?
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]){
CompLay cl = new CompLay();
}
CompLay(){
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));
add("South",p);
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}
}
1) The buttons will run from left to right along the bottom of the Frame
2) The buttons will run from left to right along the top of the frame
3) The buttons will not be displayed
4) Only button three will show occupying all of the frame
Question 17:
Question 18:
What will happen when you attempt to compile and run the following code?
}
}
1) A compile time error indicating that no run method is defined for the Thread class
2) A run time error indicating that no run method is defined for the Thread class
3) Clean compile and at run time the values 0 to 9 are printed out
4) Clean compile but no output at runtime
Question 19:
When using the GridBagLayout manager, each new component requires a new instance
of the GridBagConstraints class. Is this statement
1) true
2) false
Question 20:
Question 21:
Question 22:
Question 23:
For a class defined inside a method, what rule governs access to the variables of the
enclosing method?
Question 24:
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 25:
What will happen when you attempt to compile and run the following code
protected Hope(){
for(int i =0; i <10; i ++){
System.out.println(i);
}
}
}
Question 26:
What will happen when you attempt to compile and run the following code
Question 27:
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 28:
What will happen when you attempt to compile and run the following code
a.amethod();
}
public void amethod(){
System.out.println(j);
System.out.println(b);
}
}
Question 29:
What will happen when you attempt to compile and run the following code with the
command line "hello there"
Question 30:
What will happen when you attempt to compile and run the following code
Question 31:
What will happen when you attempt to compile and run the following code
import java.io.*;
class Base{
public static void amethod()throws FileNotFoundException{}
}
}
}
Question 32
What will happen when you attempt to compile and run this program
Question 33:
What will happen when you attempt to compile and run this code
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
Question 34:
Which option most fully describes will happen when you attempt to compile and run the
following code
Question 35:
Question 36:
Question 37:
System.out.println(Math.floor(-2.1));
1) -2
2) 2.0
3) -3
4) -3.0
Question 38:
Given the following main method in a class called Cycle and a command line of
Question 39:
Question 40:
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.
Question 41:
class Base{}
public class MyCast extends Base{
static boolean b1=false;
static int i = -1;
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 42:
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 synchronized method of an object
4) Thread scheduling algorithms are platform dependent
Question 43:
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 44:
Question 45:
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);
}
Question 46:
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 47:
System.out.println(010|4);
1) 14
2) 0
3) 6
4) 12
Question 48:
char c = 'c';
int i = 10;
double d = 10;
long l = 1;
String s = "Hello";
1)c=c+i;
2)s+=i;
3)i+=s;
4)c+=s;
Question 49:
Question 50:
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 51:
class ValHold{
public int i = 10;
}
1) 10,0, 30
2) 20,0,30
3) 20,99,30
4) 10,0,20
Question 52:
Given the following class definition, which of the following methods could be legally
placed after the comment
//Here
//Here
Question 53:
Given the following class definition which of the following can be legally placed after the
comment line //Here ?
class Base{
public Base(int i){}
}
3)this("Hello",10);
4)Base b = new Base(10);
Question 54:
Given the following class definition, which of the following statements would be legal
after the comment //Here
class InOut{
1)System.out.println(s);
2) System.out.println(iOther);
3) System.out.println(iam);
4) System.out.println(iArgs);
Question 55:
1) yield()
2) sleep(long msec)
3) go()
4) stop()
Question 56:
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 57:
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 58:
1) mousePressed(MouseEvent e){}
2) MousePressed(MouseClick e){}
3) functionKey(KeyPress k){}
4) componentAdded(ContainerEvent e){}
Question 59:
1) iterator
2) isEmpty
3) toArray
4) setText
Question 60:
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