| 21. |
What is true about Class.getInstance()?
|
||||||||
|
Answer:
Option (d) |
| 22. |
Which of these cannot be declared static?
|
||||||||
|
Answer:
Option (b) |
| 23. |
Which of the following statements are incorrect?
|
||||||||
|
Answer:
Option (d) |
| 24. |
Which of these methods must be made static?
|
||||||||
|
Answer:
Option (a) |
| 25. |
Determine output:
public class Test{
int i = 34;
public static void main(String args[]){
Test t1 = new Test();
Test t2 = new Test();
t1.i = 65;
System.out.print(t1.i);
System.out.print(t2.i);
}
}
|
||||||||
|
Answer:
Option (b) |
| 26. |
What is the output for the below code ?
class A{
int k;
boolean istrue;
static int p;
public void printValue(){
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
a.printValue();
}
}
|
||||||||
|
Answer:
Option (a) |
| 27. |
Determine output:
public class Test{
int a = 10;
public void method(int a){
a += 1;
System.out.println(++a);
}
public static void main(String args[]){
Test t = new Test();
t.method(3);
}
}
|
||||||||
|
Answer:
Option (b) |
| 28. |
What is the result of compiling and running the following code?
public class Tester{
static int x = 4;
int y = 9;
public Tester(){
System.out.print(this.x); // line 1
printVariables();
}
public static void printVariables(){
System.out.print(x); // line 2
System.out.print(y); // line 3
}
public static void main(String... args) { // line 4
new Tester();
}
}
|
||||||||
|
Answer:
Option (b) |
| 29. |
What will be the output?
public class Test{
static{
int a = 5;
}
public static void main(String args[]){
new Test().call();
}
void call(){
this.a++;
System.out.print(this.a);
}
}
|
||||||||
|
Answer:
Option (a) |
| 30. |
What will be the output of the following Java program?
class main_class
{
public static void main(String args[])
{
int x = 9;
if (x == 9)
{
int x = 8;
System.out.println(x);
}
}
}
|
||||||||
|
Answer:
Option (c) |