Questions
After the following code fragment, what is the value in fname?
String str;
int fname;
str = "Foolish boy.";
fname = str.indexOf("fool");
- 0
- 2
- -1
- 4
Which of the following is not a return type?
- boolean
- void
- public
- Button
What is the value of 'number' after the following code fragment execution?
int number = 0;
int number2 = 12
while (number < number2)
{
number = number + 1;
}
- 5
- 12
- 21
- 13
What is the data type for the number 9.6352?
- float
- double
- Float
- Double
If result = 2 + 3 * 5, what is the value and type of 'result' variable?
- 17, byte
- 25, byte
- 17, int
- 25, int
Given the following code snippet;
int salaries[];
int index = 0;
salaries = new int salaries[4];
while (index < 4)
{
salaries[index] = 10000;
index++;
}
What is the value of salaries [3]?
- 40000
- 50000
- 15000
- 10000
How many numeric data types are supported in Java?
- 8
- 4
- 2
- 6
Assume that the value 3929.92 is of type 'float'. How to assign this value after declaring the variable 'interest' of type float?
- interest = 3929.92
- interest = (Float)3929.92
- interest = 3929.92 (float)
- interest = 3929.92f
All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character) in java
- are private
- are serializable
- are immutatable
- are final
Which of the following statements is true?
- A super class is a sub set of a sub class
- class ClassTwo extends ClassOne means ClassOne is a subclass
- class ClassTwo extends ClassOne means ClassTow is a super class
- the class Class is the super class of all other classes in Java.
Which of the following statements is preferred to create a string "Welcome to Java Programming"?
- String str = “Welcome to Java Programming”
- String str = new String( “Welcome to Java Programming” )
- String str; str = “Welcome to Java Programming”
- String str; str = new String (“Welcome to Java Programming” )
Which of the following statements is true?
- The default char data type is a space( ' ' ) character.
- The default integer data type is 'int' and real data type is 'float'
- The default integer data type is 'long' and real data type is 'float'
- The default integer data type is 'int' and real data type is 'double'
Consider the following code snippet. What will be assigned to the variable fourthChar, if the code is executed?
String str = new String(“Java”);
char fourthChar = str.charAt(4);
-
a -
v - throws StringIndexOutofBoundsException
- null characater
What kind of thread is the Garbage collector thread is?
- Non daemon thread
- Daemon thread
- Thread with dead state
- None of the above
When a thread terminates its processing, into what state that thread enters?
- Running state
- Waiting state
- Dead state
- Beginning state
Which statement is true?
- HashTable is a sub class of Dictionary
- ArrayList is a sub class of Vector
- LinkedList is a subclass of ArrayList
- Vector is a subclass of Stack
Which of the following statements declare class Sample to belong to the payroll.admindept package?
- package payroll;package admindept;
- import payroll.*;
- package payroll.admindept.Sample;
- import payroll.admindept.*;
Which of these statements is true?
- LinkedList extends List
- AbstractSet extends Set
- HashSet extends AbstractSet
- WeakHashMap extends HashMap
The class java.lang.Exception is
- protected
- extends Throwable
- implements Throwable
- serializable
Which three guarantee that a thread will leave the running state?
yield()
wait()
notify()
notifyAll()
sleep(1000)
aLiveThread.join()
Thread.killThread()
- 1, 2 and 4
- 2, 5 and 6
- 3, 4 and 7
- 4, 5 and 7
What will be the output of the program?
class A
{
final public int GetResult(int a, int b) { return 0; }
}
class B extends A
{
public int GetResult(int a, int b) {return 1; }
}
public class Test
{
public static void main(String args[])
{
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}
- x = 0
- x = 1
- Compilation fails.
- An exception is thrown at runtime.
The code snippet
if( "Welcome".trim() == "Welcome".trim() )
System.out.println("Equal");
else
System.out.println("Not Equal");
will
- compile and display “Equal”
- compile and display “Not Equal”
- cause a compiler error
- compile and display NULL
class HappyGarbage01
{
public static void main(String args[])
{
HappyGarbage01 h = new HappyGarbage01();
h.methodA(); /* Line 6 */
}
Object methodA()
{
Object obj1 = new Object();
Object [] obj2 = new Object[1];
obj2[0] = obj1;
obj1 = null;
return obj2[0];
}
}
Where will be the most chance of the garbage collector being invoked?
- After line 9
- After line 10
- After line 11
- Garbage collector never invoked in methodA()
What will be the output of the program?
class SC2
{
public static void main(String [] args)
{
SC2 s = new SC2();
s.start();
}
void start()
{
int a = 3;
int b = 4;
System.out.print(" " + 7 + 2 + " ");
System.out.print(a + b);
System.out.print(" " + a + b + " ");
System.out.print(foo() + a + b + " ");
System.out.println(a + b + foo());
}
String foo()
{
return "foo";
}
}
- 9 7 7 foo 7 7foo
- 72 34 34 foo34 34foo
- 9 7 7 foo34 34foo
- 72 7 34 foo34 7foo
What will be the output of the program?
class BoolArray
{
boolean [] b = new boolean[3];
int count = 0;
void set(boolean [] x, int i)
{
x[i] = true;
++count;
}
public static void main(String [] args)
{
BoolArray ba = new BoolArray();
ba.set(ba.b, 0);
ba.set(ba.b, 2);
ba.test();
}
void test()
{
if ( b[0] && b[1] | b[2] )
count++;
if ( b[1] && b[(++count - 2)] )
count += 7;
System.out.println("count = " + count);
}
}
- count = 0
- count = 2
- count = 3
- count = 4