Question 1)
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"
MyDoubts
Q1)True that Run() is a callback function but can it be considered here as an inner function to void piggy(String) because start() which is responsible for it being called is with in the scope of this function??
Q2)Answer to the above question happens to be 4 but will sName (being static) remain uneffected by the statement preceding start() ?
Q3)Is it a hard and fast rule that run should always be public void run() ?? (Am i correct if i answer it like ... since i dont call it i cannot change its signature ??)
Q4)Would sName have been defined in Run() if it werent declared static ?
------------------------------------------------------------------------------------------------------------
Question 2)
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
MyDoubts
Q1)What is a bitset collection?
------------------------------------------------------------------------------------------------------------
Question 3)How do you change the current layout manager for a container
1) Use the setLayout method
2) Once created you cannot change the current layout manager of a component
3) Use the setLayoutManager method
4) Use the updateLayout method
MyDoubts
Q1) Say I add components to a container using a specified Layout and then when i change the
layout what happens to the components will they be rearranged according to the new component ?
------------------------------------------------------------------------------------------------------------
Question 4) What will happen when you attempt to compile and run the following code
Question->
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
Mydoubts
Answer to this question has been given as 4 but when static methods of a class cannot be
overridden then how can the answer be 4 ?
------------------------------------------------------------------------------------------------------------
Question 5)
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 synchronized method of an object
4) Thread scheduling algorithms are platform dependent
Mydoubts
Wht does he mean by obtaining mutually exclusive lock on any object?
------------------------------------------------------------------------------------------------------------
Question 6)
Which of the following statements are true?
1) The garbage collection algorithm in Java is vendor implemented
2) The size of primitives is platform dependent
3) The default type for a numerical literal with decimal component is a float.
4) You can modify the value in an Instance of the Integer class with the setValue method
Mydoubts
Ans has been given as 1 .... Why is answer 2 wrong ?? when size of int on unix and dos isnt the same.
------------------------------------------------------------------------------------------------------------
Question 7)
Which of the following statements are true?
1) A method cannot be overloaded to be less public in a child class
2) To be overridden a method must have the same name and parameter types
3) To be overridden a method must have the same name, parameter and return types
4) An overridden method must have the same name, parameter names and parameter types
answer Given (3) To be overriden a method must have the same name, parameter and return types
Reson - Option 1 is a sneaky one in that it should read overriden not overloaded. An overriden
method must also have the same return type. Parameter names are purely a programmer
convenience and are not a factor in either overloading and overriding. Parameter order
is a factor however.
MyDoubt
But method overriding can widen the scope of a method then y is 1 wrong ?
------------------------------------------------------------------------------------------------------------
Question 8)
Given the following class
public class ZeroPrint{
public static void main(String argv[]){
int i =0;
//Here
}
}
Which of the following lines if placed after the comment //Here will print out 0.
1) System.out.println(i++);
2) System.out.println(i+'0');
3) System.out.println(i);
4) System.out.println(i--);
Answer to Question 8)
1) System.out.println(i++);
3) System.out.println(i);
4) System.out.println(i==);
The options for this question might look suspiciously easy if you are not aware of the effects of
the post-increment operators. The ++ and == operations for examples 1 and 4 only come into
effect after the output operations, ie after whatever else is done to them on that line of
code. Option 2 should be fairly obvious as you should know that the single quote characters
indicate a char value, ie storing the character rather than the numberical value for 0.
MyDoubt
y is option 2 wrong ?