|
|
SCJP
Sample questions
The following questions
are sample questions for SCJP
If any queries regarding the questions or answers please mail us |
|
31)
class c2{
final int i1;
c2()
{
i1=i1+1;
}
{
i1=2;
}
public static void main(String a[])
{
c2 ob1=new c2();
System.out.println(ob1.i1);
}
}
compile time error
prints 3
prints 2
none of the above
Explanation:
No Explanation Available
Ans: 1 |
32)
class C{
public static void main(String a[])
{
int i1=9;
int i2;
if(i1>3)
{
i2=8;
}
System.out.println(i2);
}}
compile time error
Runtim error
prints 8
prints 0
None of the above
Explanation:
since variable i1 is not final the value is not known at compiletime
itself.so generate compile time error
Ans: 1
33)
class A extends Thread {
public void run() {
System.out.print("A");
}
}
class B {
public static void main (String[] args) {
A a = new A();
a.start();
a.start(); // 1
}
}
compile time error
Runtime Exception
the code compile and runs fine
none of the above
Explanation:
If the start method is invoked on a thread that is already running,
then an IllegalThreadStateException will probably be thrown
Ans: 2
34)
class c1
{
static{
System.out.println("static");
}
public static void main(String a[])
{
System.out.println("main");
}
}
prints static main
prints main
prints main static
compiletime error
none of the above
Explanation:
No Explanation Available
Ans: 1
35)
class A{
static String m(float i) {return "float";}
static String m(double i) {return "double";}
public static void main (String[] args) {
int a1 = 1; long b1 = 2;
System.out.print(m(a1)+","+ m(b1));
}}
prints float,foat
prints float,double
prints double,double
compile time error
None of the above
Explanation:
No Explanation Available
Ans: 1
36)
When a byte is added to a char, what is the type of the result?
byte
int
long
non of the above
Explanation:
The result of all arithmetic performed with the binary operators (not
the assignment operators) is an int, a long, a float, or a double. Here
byte and char are promoted to int, so the result is an int.
Ans: 2
37)
class C extends Thread{
public static void main(String argv[]){
C b = new C();
b.run();
}
public void start(){
for (int i = 0;
i <10; i++){
System.out.println("Value of i = " + i);
}
}
}
compile time error
runtime Exception
prints values from 0 to 9
None of the above
Explanation:
No Explanation Available
Ans: 4
38)
What is the signature of the run() method of the Runnable interface?
void run()
public void run(Runnable target)
public void run()
public static void run()
Explanation:
No Explanation Available
Ans: 3
39)
class C{
public static void main(String args[]) {
int a = 1;
a += ++a + a++;
System.out.print(a);
}}
compile time error
Runtime Exception
Prints 5
Prints 4
None of the above
Explanation:
No Explanation Available
Ans: 3
40)
interface I
{ //1
public class Inner { ///2
Inner ( ) {
System .out . println ( "Inner Created" ) ;
}
};
};
compile time error at line 1
compile time error at line 2
the code compiles fine
none of the above
Explanation:
No Explanation Available
Ans: 3
Go To Index
|
|
|