PART 1
1.public static void main(String args[]) {
Boolean a[]=new Boolean[4];
int I= 1;
System.out.println(a[I]); }
What will be printed?
Compilation Error in Line 2
Compilation Error in line 4
Exception in Line 4
Will print true
Will print false
Will print null
Ans:F
2.
public static void main(String args[]) {
Integer b= new Integer(10);
Add(b);
System.out.println(b.intvalue());
}
void Add(Integer b)
{
int I= b.intvalue();
I+=3;
b= new Integer(I)
}
What will be printed out?
Will print 13
Will print 10
Compilation Error in Line 4 ?. implicit conversion to Integer to
String is not possible
Compilation Error in line 10 you can't re initialize a Wrapper
class
Exception in Line 10
Ans:b
class text{
public static void main(String args[])
{
String a =args[1];
String b =args[2];
String c =args[3];
}
}
if you will execute Java text cat dog sheep what will be the value of
the 'c' ?
cat
dog
sheep
Compilation Error
Exception will occur
Ans:E
4. public static void main(String args[])
{
Float f=new Float(4.2f);
Float c;
Double d=new Double(4.2);
float fl=4.2f;
c=f;
}
which will return true?. Select all
f.equls(d)
c==f
c==d
c.equls(f)
Ans:B,D
5. public static void main(String args[])
{
String s;
System.out.println("s = "+s);
}
what will be printed out?
Compilation Error
An Exception will occur
Will print s= null
Will print s=
Ans:A
6. class s extends Thread{int j=0;
public void run() {
try{Thread.sleep(5000);}
catch(Exception e){}
j=100;
}
public static void main(String args[])
{
s t1=new s();
t1.start();
System.out.println(t1.j);
}
}
what you have to do to ensure that 'j' will print 100
you have make t1 as Daemon Thread
You have join the t1 to main
You have to suspend the main when the thread starts and resume it after
the value of 'j' is set to 100
You have to interrupt the main thread
Ans:B
7. What will happen if you compile/run this code?
1: public class Q1 implements Runnable
2: {
3: public void run(String s)
4: {
5: System.out.println("Before start Thread :"+s);
6:
7: System.out.println("After stop of Thread :"+s);
8: }
9:
10: public static void main(String[] args)
11: {
12: Q1 a = new Q1();
13: Thread t=new Thread(a);
14: t.start();}
15: }
A) Compilation error at line 1
B) Runtime exception at line 13.
C) Compilation error at line 14
D) Prints "Before start of Thread "
After Start of Thread
Ans:A
8. class s implements Runnable{
int x=0,y=0;
int addX(){x++; return x;}
int addY(){y++; return y;}
public void run()
{
for(int i=0;i
System.out.println(addX()+""+addY());
}
public static void main(String args[])
{
s run=new s();
Thread t1=new Thread(run);
Thread t2=new Thread(run);
t1.start();
t2.start();
}
}
Compile time Error There is no start method
Will print in this order 11 22 33厖
Will print but not exactly in an order (eg: 123124 3厖)
Will print in this order 12 3厖123厖
Will print in this order 123厖?.
Ans:C
9.
class s implements Runnable{
int x=0,y=0;
synchronized void addX(){x++; }
synchronized void addY(){y++; }
void addXY(){x++;y++;}
boolean check() { return (xy)? true:false;)
public void run()
{
////
System.out.println(check()); }
public static void main(String args[])
{ s run=new s();
Thread t1=new Thread(run);
Thread t2=new Thread(run);
t1.start();
t2.start();
}
}
If this methods are called in which order the check will return true?
Select all that apply
call addX() and addY() simultaneously for number of times in run()
call addY() and addX() simultaneously for number of times in run()
all addXY() for number of times in run()
Ans:B,C
10. What is the name of the method used to start a thread execution?
A. init();
B. start();
C. run();
D. resume();
Ans:B
11. Which two methods may not directly cause a thread to stop
executing?
A. sleep();
B. stop();
C. yield();
D. wait();
E. notify();
F. notifyAll()
G. synchronized()
Ans:EF
12. class Outer{
class Inner{}
}
How will you create an instance of Inner Class out side? Select 2
Inner a= new Inner();
Outer o= new Outer();Inner a= new o.Inner();
Outer o= new Outer();Outer.Inner a= new o.Inner();
Outer.Inner a= new Outer().new Inner();
Ans:CD
13. What a static inner class can Access select one
A. Any variables in the enclosing scope
B. Final variables in the enclosing scope
C. Static variables declared in side the method
D. Static variables declared in side the outer class
Ans:D
14. What is true about inner class? Select one
an Inner class can access all variables in the any enclosing scope
an Inner class can access all variables in the enclosing scope
an inner class can be declared as private
an Anonymous inner class can be extended from class and can implement
an interface
Ans:C
15. A ----- is a class that is a collection which cannot contain any
duplicate elements which maintains its elements in ascending order.
SortedSet
Set
Sorted Map
Collection
TreeSet
Ans: A
16. What is true about Map select one
A map will order the elements in an order according the key
A map will use unique key to store value
A map will use unique key to identify value inside the map
Ans:C
17. Which Method Returns the parent part of the pathname of this File
object, or null if the name has no parent part?
getParent()
getParentDir()
getParentDirectory()
parentDirectory()
Ans:a
18. Which class should be used in situations that require writing
characters rather than bytes.
LineNumberWriter
PrintWriter
PrintStream
PrintOutputReader
Ans:B
19. To Write End of a File f=new File(C:\\hello.txt");
new RandomAccessFile(f,"rw").writeByte(?;
FileInputStream fis=new FileInputStream(f,true);
DataInputStream d=new DatainputStream(fis);
d.writeBytes(?
FilterInputStream fis=new FilterInputStream(f,true);
DataInputStream d=new DatainputStream(fis);
d.writeBytes(?
D. FileOutputStream fis=new FileOutputStream(f);
DataOutputStream d=new DataOutputStream(fis);
d.writeBytes(?
E