question 1)
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;
answer to question 1
--------------------------------------------------------------------------------
question 2)
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磘 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
answer to question 2
--------------------------------------------------------------------------------
question 3)
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{}
answer to question 3
--------------------------------------------------------------------------------
question 4)
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
answer to question 4
--------------------------------------------------------------------------------
question 5)
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 raised: ’java.lang.arrayindexoutofboundsexception: 2’
answer to question 5
--------------------------------------------------------------------------------
question 6)
which of the following are keywords or reserved words in java?
1) if
2) then
3) goto
4) while
which of the following statements are true?
1) methods cannot be overriden to be more private
2) static methods cannot be overloaded
3) private methods cannot be overloaded
4) an overloaded method cannot throw exceptions not checked in the base class
answer to question 16
--------------------------------------------------------------------------------
question 17)
what will happen if you attempt to compile and run the following code?
class base {}
class sub extends base {}
class sub2 extends base {}
public class cex{
public static void main(string argv[]){
base b=new base();
sub s=(sub) b;
}
}
1) compile and run without error
2) compile time exception
3) runtime exception
answer to question 17
--------------------------------------------------------------------------------
question 18)
which of the following statements are true?
1) system.out.println( -1 >>> 2);will output a result larger than 10
2) system.out.println( -1 >>> 2); will output a positive number
3) system.out.println( 2 >> 1); will output the number 1
4) system.out.println( 1 <<< 2); will output the number 4
answer to question 18
--------------------------------------------------------------------------------
question 19)
what will happend when you attempt to compile and run the following code?
public class tux extends thread{
static string sname = ’vandeleur’;
public static void main(string argv[]){
tux t = new tux();
t.piggy(sname);
system.out.println(sname);
}
public void piggy(string sname){
sname = sname ’ wiggy’;
start();
}
public void run(){
for(int i=0;i < 4; i ){
sname = sname ’ ’ i;
}
}
}
1) compile time error
2) compilation and output of ’vandeleur wiggy’
3) compilation and output of ’vandeleur wiggy 0 1 2 3’
4) compilation and probably output of ’vandeleur’ but possible output of ’vandeleur 0 1 2 3’
answer to question 19
--------------------------------------------------------------------------------
question 20)
what will be displayed when you attempt to compile and run the following code
//code start
question 29)
what is the result of the following operation?
system.out.println(4 | 3);
1) 6
2) 0
3) 1
4) 7
answer to question 29
--------------------------------------------------------------------------------
question 30)
public class myclass1 {
public static void main(string argv[]){ }
/*modifier at xx */ class myinner {}
}
what modifiers would be legal at xx in the above code?
1) public
2) private
3) static
4) friend
answer to question 30
--------------------------------------------------------------------------------
question 31)
what will happen when you attempt to compile and run the following code?
public class holt extends thread{
private string sthreadname;
public static void main(string argv[]){
holt h = new holt();
h.go();
}
holt(){}
holt(string s){
sthreadname = s;
}
public string getthreadname(){
return sthreadname;
}
public void go(){
holt first = new holt(’first’);
first.start();
holt second = new holt(’second’);
second.start();
}
public void start(){
for(int i = 0; i < 2; i ){
system.out.println(getthreadname() i);
try{
thread.sleep(100);
} catch(interruptedexception e){system.out.println(e.getmessage());}
}
}
}
1) compile time error
2) output of first0, second0, first0, second1
3) output of first0, first1, second0, second1
4) runtime error
answer to question 31
--------------------------------------------------------------------------------
question 32)
an applet has its layout manager set to the default of flowlayout.
what code would be correct to change to another layout manager.
1) setlayoutmanager(new gridlayout());
2) setlayout(new gridlayout(2,2));
3) setgridlayout(2,2);
4) setborderlayout();
answer to question 32
--------------------------------------------------------------------------------
question 33)
what will happen when you attempt to compile and run the following code?.
class background implements runnable{
int i=0;
public int run(){
while(true){
question 45
what will happen when you try compiling and running this code?
public class ref{
public static void main(string argv[]){
ref r = new ref();
r.amethod(r);
}
public void amethod(ref r){
int i=99;
multi(r);
system.out.println(i);
}
public void multi(ref r){
r.i = r.i*2;
}
}
1) error at compile time
2) an output of 99
3) an output of 198
4) an error at runtime
answer to question 45
--------------------------------------------------------------------------------
question 46)
you need to create a class that will store unique object elements.
you do not need to sort these elements but they must be unique.
what interface might be most suitable to meet this need?
1)set
2)list
3)map
4)vector
answer to question 46
--------------------------------------------------------------------------------
question 47)
which of the following will successfully create an instance of the vector
class and add an element?
1) vector v=new vector(99);
v[1]=99;
2) vector v=new vector();
v.addelement(99);
3) vector v=new vector();
v.add(99);
4 vector v=new vector(100);
v.addelement(’99’);
answer to question 47
--------------------------------------------------------------------------------
question 48)
you have created a simple frame and overridden the paint method as follows
public void paint(graphics g){
g.drawstring(’dolly’,50,10);
}
what will be the result when you attempt to compile and run the program?
1) the string ’dolly’ will be displayed at the centre of the frame
2) an error at compilation complaining at the signature of the paint method
3) the lower part of the word dolly will be seen at the top of the frame, with the top hidden.
4) the string ’dolly’ will be shown at the bottom of the frame.
answer to question 48
--------------------------------------------------------------------------------
question 49)
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
answer to question 49
question 56)
you are using the gridbaglayout manager to place a series of buttons on a frame.
you want to make the size of one of the buttons bigger than the text it contains.
which of the following will allow you to do that?
1) the gridbaglayout manager does not allow you to do this
2) the setfill method of the gridbaglayout class
3) the setfill method of the gridbagconstraints class
4) the fill field of the gridbagconstraints class
answer to question 56
--------------------------------------------------------------------------------
question 57)
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
answer to question 57
--------------------------------------------------------------------------------
question 58)
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
answer to question 58
--------------------------------------------------------------------------------
question 59)
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’);