TEST YOUR JAVA KNOWLEDGE
1.What will be the output of the program?
class s implements Runnable
{
int
x, y;
public void run()
{
for(int i = 0; i < 1000; i++)
synchronized(this)
{
x = 12;
y = 12;
}
System.out.print(x + " " + y + " ");
}
public static void main(String args[])
{
s run = new s();
Thread t1 = new Thread(run);
Thread t2 = new Thread(run);
t1.start();
t2.start();
}
}
A) DeadLock
B) It print 12 12 12 12
C) Compilation Error
D) Cannot determine output.
2.Which one of these lists contains only Java
programming language keywords?
A) class, if, void, long, Int, continue
B) goto, instanceof, native, finally,
default, throws
C) try, virtual, throw, final, volatile,
transient
D) strictfp, constant, super, implements, do
E) byte, break, assert, switch, include
3.public void test(int x)
{
int
odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
Which statement is true?
A) Compilation fails.
B) "odd" will always be output.
C) "even" will always be output.
D) "odd" will be output for odd
values of x, and "even" for even values.
4.What will be the output of the program?
public class SwitchTest
{
public static void main(String[] args)
{
System.out.println("value =" + switchIt(4));
}
public static int switchIt(int x)
{
int j = 1;
switch (x)
{
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default: j++;
}
return j + x;
}
}
A) value = 2
B) value = 4
C) value = 6
D) value = 8
5.Which constructs an anonymous inner class
instance?
A) Runnable r = new Runnable() { };
B) Runnable r = new Runnable(public void
run() { });
C) Runnable r = new Runnable { public void
run(){}};
D) System.out.println(new Runnable() {public
void run() { }});
6. class Boo
{
Boo(String s) { }
Boo() { }
}
class Bar extends Boo
{
Bar() { }
Bar(String s) {super(s);}
void zoo()
{
//
insert code here
}
}
which one create an anonymous inner class
from within class Bar?
A) Boo f = new Boo(24) { };
B) Boo f = new Bar() { };
C) Bar f = new Boo(String s) { };
D) Boo f = new Boo.Bar(String s) { };
7.What will be the output of the program?
class
PassS
{
public static void main(String [] args)
{
PassS p = new PassS();
p.start();
}
void start()
{
String s1 = "slip";
String s2 = fix(s1);
System.out.println(s1 + " " + s2);
}
String fix(String s1)
{
s1 = s1 + "stream";
System.out.print(s1 + " ");
return "stream";
}
}
A) slip stream
B) slipstream stream
C) stream slip stream
D) slipstream slip stream
8.What will be the output of the program?
public class Test
{
public static void leftshift(int i, int j)
{
i <<= j;
}
public static void main(String args[])
{
int i = 4, j = 2;
leftshift(i, j);
System.out.printIn(i);
}
}
A) 2
B) 4
C) 8
D) 16
9.What is the value returned by function
compareTo() if the invoking string is less than the string compared?
A) zero
B) value less than zero
C) value greater than zero
D) None of the mentioned
10. Which of these class is implemented by
FilterInputStream class?
11. Which of these class contains the methods
print() & println()?
B) System.out
C) BUfferedOutputStream
D) PrintStream
12. Which of these is specified by a File object?
A)
a file in disk
B)
directory path
C)
directory in disk
D)
None of the mentioned
13. Which of these is a mechanism for naming and
visibility control of a class and its content?
A)
Object
B)
Packages
C)
Interfaces
D)
None of the Mentioned.
14. Which of the following is incorrect statement
about packages?
A)
Package defines a namespace
in which classes are stored.
B)
A package can contain other
package within it.
C)
Java uses file system
directories to store packages.
D)
A package can be renamed
without renaming the directory in which the classes are stored.
15.What is the order of precedence
(highest to lowest) of following operators?
1. &
2. ^
3. ?:
A)
1 -> 2 -> 3
B)
2 -> 1 -> 3
C)
3 -> 2 -> 1
D)
2 -> 3 -> 1
16. What is the
output of this program?
class A {
public int i,j;
A() {
i = 1;
j = 2;
}
}
class
B extends A{
int
a;
B() {
super();
}
}
class
super_use{
public
static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + " " + obj.j)
}
}
A) 1 2
B) 2 1
C) Runtime Error
D) Compilation Error
B) 2 1
C) Runtime Error
D) Compilation Error
17. What is the
output of this program?
abstract class A {
int i;
abstract void display();
}
class B extends
A {
int j;
void display() {
System.out.println(j);
}
}
class Abstract_demo {
public static
void main(String
args[])
{
B obj = new B();
obj.j=2;
obj.display();
}
}
A) 0
B) 2
C) Runtime Error
D) Compilation Error
B) 2
C) Runtime Error
D) Compilation Error
18. Which of the
following is incorrect statement regarding the use of generics and
parameterized types in Java?
A) Generics provide type safety by shifting more type checking responsibilities
to the compiler.
B) Generics and parameterized types eliminate the need for down casts when using Java Collections.
C) When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes.
D) All of the mentioned
B) Generics and parameterized types eliminate the need for down casts when using Java Collections.
C) When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes.
D) All of the mentioned
19. Which of the
following keywords are used for lower bounding a wild card?
A) extends
B) super
C) class
D) lower
B) super
C) class
D) lower
20. Which of these
method of Locale class can be used to obtain country of operation?
A) getCountry()
B) whichCountry()
C) DisplayCountry()
D) getDisplayCountry()
B) whichCountry()
C) DisplayCountry()
D) getDisplayCountry()
21. Which of these
methods can be used to know which key is pressed?
A) getKey()
B) getModifier()
C) getActionKey()
D) getActionEvent()
B) getModifier()
C) getActionKey()
D) getActionEvent()
22. How
many bits are used to represent Unicode ?
A) 8 bits
B) 16 bits
C) 24 bits
D) 32 bits
B) 16 bits
C) 24 bits
D) 32 bits
23. Which of the following is not type of inner classes ?
A) Simple Inner Class
B) Static Nested Inner Class
C) Method Nested Static Inner Class
D) Anonymous Inner Class
B) Static Nested Inner Class
C) Method Nested Static Inner Class
D) Anonymous Inner Class
24.
Choose the proper operator precedence when evaluating an Expression?
1.
Comparisons
2.
Logical operations
3. Increment
4.
Arithmetic operations
A)
3-4-1-2
B)
1-2-4-3
C)
4-3-1-2
D) 2-1-4-3
25. Java is designed for the
distributed environment of the Internet, because it handles ________ protocols
A) UDP
B) TCP/IP
C) FTP
D) TEL
26. x=10,y=5
if(x>=9&&y<=8)
z=x+y
else
z=x-y
What would be value of z after executing the following statement
A)
15
B)
5
C)
13
D)
none of these
27.The _______ keyword is used to
derive a class from a superclass. The _________keyword is used to declare
classes that define common properties and behavior of other classes
A) Public ,friend
B) abstract ,extends ,
C) extends,abstract
D) friend ,Public
28. A class can be declared as
_______ if you do not want the class to be subclassed. Using the __________ keyword
we can abstract a class interface from its implementation.
A) protected ,interface
B) final,interface
C) public,friend
D) final,protected
29. The term exception denotes an
________ event .Java handles exceptions the___________ way.
A)
exceptional ,object-oriented
B) traditional, object-oriented
C) exceptional, procedural
D) friend ,Public
FOR MORE INFORMATION.. CLICK HERE... https://www.facebook.com/gkcclasses/
Comments
Post a Comment