1. What is output of below code?
A. Both x and y
B. Only x
C. Only y
D. Both a and b
B. Only x
(b) What are the instance variables?
A. Both x and y
B. Only x
C. Only y
D. Both a and b
C. Only y
(c) What is the output of above code?
A. 5 6 1 2 7
B. 5 6 1 2 2
C. 5 6 1 2 2
D. 5 6 2 2 2
D. 5 6 2 2 2
2. What is output of bellow code?
B. BBB DDD
C. AAA CCC
D. BBB CCC
C. AAA CCC
3. What is output of bellow code?
B. XyZabc
C. XYZabc
D. xyzabc
D. xyzabc
4. What is output of bellow code?
B. 1
C. Compiler Error
D. 0
D. 0
5. What is output of bellow code?
B. complete
C. Runtime Error
A. Compiler Error
6. What is output of bellow code?
B. +3.0
C. -3.0
D. NaN
D. NaN
7. What is output of bellow code?
B. 42
C. 43.5
D. Bad Number
A. 43
8. What is output of bellow code?
B. Runtime Exception
C. 5
D. 5.0
C. 5
9. What is output of bellow code?
B. app
C. apea
D. appp
B. app
10. What is output of bellow code?
B. abc def def
C. abc ghi def
D. ghi def abc
C. abc ghi def
11. What is output of bellow code?
B. cava javac
C. cava java
D. java java
A. java javac
12. What is output of bellow code?
B. Pine
C. Oak
D. Oops
A. Tree
13. What is output of bellow code?
B. wookkeewoo
C. wbookkeeperwoo
D. Runtime Error
A. Compiler Error
14. What is output of bellow code?
B. dccd
C. accd
D. abcd
D. abcd
15. What is output of below code?
B. StackOverflowError Exception
C. Hello
D. Display Hello Infinite Times
B. StackOverflowError Exception
16. What is output of below code?
B. 5 10
C. 5 16
D. 5 21
D. 5 21
17. What is output of bellow code?
B. s1 != s2
C. Compiler Error
D. Runtime Error
A. s1 == s2
18. What is output of bellow code?
B. llo llo
C. Hello Hello
D. ello ll
A. llo ll
19. What is output of bellow code?
B. true false true true
C. true false true false
D. false false false false
B. true false true true
public class Test {
public static int x = 7;
public int y = 3;
public static void main(String[] args) {
Test a = new Test();
Test b = new Test();
a.y = 5;
b.y = 6;
a.x = 1;
b.x = 2;
System.out.print(a.y + " " + b.y + " " + a.x + " " + b.x + " ");
System.out.print(Test.x);
}
}
(a) What are the class variables?public static int x = 7;
public int y = 3;
public static void main(String[] args) {
Test a = new Test();
Test b = new Test();
a.y = 5;
b.y = 6;
a.x = 1;
b.x = 2;
System.out.print(a.y + " " + b.y + " " + a.x + " " + b.x + " ");
System.out.print(Test.x);
}
}
A. Both x and y
B. Only x
C. Only y
D. Both a and b
B. Only x
(b) What are the instance variables?
A. Both x and y
B. Only x
C. Only y
D. Both a and b
C. Only y
(c) What is the output of above code?
A. 5 6 1 2 7
B. 5 6 1 2 2
C. 5 6 1 2 2
D. 5 6 2 2 2
D. 5 6 2 2 2
2. What is output of bellow code?
public class Test {
public static void main(String[] args) {
String s = "foo";
Object o = (Object) s;
if (s.equals(o)) {
System.out.print("AAA" + " ");
} else {
System.out.print("BBB" + " ");
}
if (o.equals(s)) {
System.out.print("CCC" + " ");
} else {
System.out.print("DDD" + " ");
}
}
}
A. AAA DDDpublic static void main(String[] args) {
String s = "foo";
Object o = (Object) s;
if (s.equals(o)) {
System.out.print("AAA" + " ");
} else {
System.out.print("BBB" + " ");
}
if (o.equals(s)) {
System.out.print("CCC" + " ");
} else {
System.out.print("DDD" + " ");
}
}
}
B. BBB DDD
C. AAA CCC
D. BBB CCC
C. AAA CCC
3. What is output of bellow code?
public class Test {
public static void main(String[] args) {
String x = "xyz";
x.toUpperCase();
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);
}
}
A. xYzabcpublic static void main(String[] args) {
String x = "xyz";
x.toUpperCase();
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);
}
}
B. XyZabc
C. XYZabc
D. xyzabc
D. xyzabc
4. What is output of bellow code?
public class Test {
public static void main(String[] args) {
int i = (int) Math.random();
System.out.println(i);
}
}
A. Any Random numberpublic static void main(String[] args) {
int i = (int) Math.random();
System.out.println(i);
}
}
B. 1
C. Compiler Error
D. 0
D. 0
5. What is output of bellow code?
class A {
public A(int x) {
}
}
class B extends A {
}
public class Test {
public static void main(String args[]) {
A a = new B();
System.out.println("complete");
}
}
A. Compiler Errorpublic A(int x) {
}
}
class B extends A {
}
public class Test {
public static void main(String args[]) {
A a = new B();
System.out.println("complete");
}
}
B. complete
C. Runtime Error
A. Compiler Error
6. What is output of bellow code?
public class Test {
public static void main(String[] args) {
double value = -9.0;
System.out.println(Math.sqrt(value));
}
}
A. Compiler Errorpublic static void main(String[] args) {
double value = -9.0;
System.out.println(Math.sqrt(value));
}
}
B. +3.0
C. -3.0
D. NaN
D. NaN
7. What is output of bellow code?
public class Test {
public static void main(String[] args) {
String s = "42";
try {
s = s.concat(".5");
double d = Double.parseDouble(s);
s = Double.toString(d);
int x = (int) Math.ceil(Double.valueOf(s));
System.out.println(x);
} catch (NumberFormatException e) {
System.out.println("Bad Number");
}
}
}
A. 43public static void main(String[] args) {
String s = "42";
try {
s = s.concat(".5");
double d = Double.parseDouble(s);
s = Double.toString(d);
int x = (int) Math.ceil(Double.valueOf(s));
System.out.println(x);
} catch (NumberFormatException e) {
System.out.println("Bad Number");
}
}
}
B. 42
C. 43.5
D. Bad Number
A. 43
8. What is output of bellow code?
interface K {
int k = 5;
}
public class Test implements K {
public static void main(String args[]) {
int i;
Test test = new Test();
i = test.k;
i = Test.k;
i = K.k;
System.out.println(i);
}
}
A. Compiler Errorint k = 5;
}
public class Test implements K {
public static void main(String args[]) {
int i;
Test test = new Test();
i = test.k;
i = Test.k;
i = K.k;
System.out.println(i);
}
}
B. Runtime Exception
C. 5
D. 5.0
C. 5
9. What is output of bellow code?
public class Test {
public static void main(String[] args) {
String a = "newspaper";
a = a.substring(5, 7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);
}
}
A. apeppublic static void main(String[] args) {
String a = "newspaper";
a = a.substring(5, 7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);
}
}
B. app
C. apea
D. appp
B. app
10. What is output of bellow code?
public class Test {
public static void main(String[] args) {
String s1 = "abc";
String s2 = "def";
String s3 = s2;
s2 = "ghi";
System.out.println(s1 + " " + s2 + " " + s3);
}
}
A. abc ghi ghipublic static void main(String[] args) {
String s1 = "abc";
String s2 = "def";
String s3 = s2;
s2 = "ghi";
System.out.println(s1 + " " + s2 + " " + s3);
}
}
B. abc def def
C. abc ghi def
D. ghi def abc
C. abc ghi def
11. What is output of bellow code?
public class Test {
public static void stringReplace(String text) {
text = text.replace('j', 'c');
}
public static void bufferReplace(StringBuffer text) {
text = text.append("c");
}
public static void main(String args[]) {
String textString = new String("java");
StringBuffer textBuffer = new StringBuffer("java");
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println(textString + " " + textBuffer);
}
}
A. java javacpublic static void stringReplace(String text) {
text = text.replace('j', 'c');
}
public static void bufferReplace(StringBuffer text) {
text = text.append("c");
}
public static void main(String args[]) {
String textString = new String("java");
StringBuffer textBuffer = new StringBuffer("java");
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println(textString + " " + textBuffer);
}
}
B. cava javac
C. cava java
D. java java
A. java javac
12. What is output of bellow code?
class Tree {
}
class Pine extends Tree {
}
class Oak extends Tree {
}
public class Forest {
public static void main(String[] args) {
Tree tree = new Oak();
if (tree instanceof Pine)
System.out.println("Pine");
else if (tree instanceof Tree)
System.out.println("Tree");
else if (tree instanceof Oak)
System.out.println("Oak");
else
System.out.println("Oops ");
}
}
A. Tree}
class Pine extends Tree {
}
class Oak extends Tree {
}
public class Forest {
public static void main(String[] args) {
Tree tree = new Oak();
if (tree instanceof Pine)
System.out.println("Pine");
else if (tree instanceof Tree)
System.out.println("Tree");
else if (tree instanceof Oak)
System.out.println("Oak");
else
System.out.println("Oops ");
}
}
B. Pine
C. Oak
D. Oops
A. Tree
13. What is output of bellow code?
public class Test {
public static void main (String [] args){
String d = "bookkeeper";
d.substring(1,7);
d = "w" + d;
d.append("woo");
System.out.println(d);
}
}
A. Compiler Errorpublic static void main (String [] args){
String d = "bookkeeper";
d.substring(1,7);
d = "w" + d;
d.append("woo");
System.out.println(d);
}
}
B. wookkeewoo
C. wbookkeeperwoo
D. Runtime Error
A. Compiler Error
14. What is output of bellow code?
public class Test {
public static void main(String[] args) {
String a = "ABCD";
String b = a.toLowerCase();
b.replace('a', 'd');
b.replace('b', 'c');
System.out.println(b);
}
}
A. dbcdpublic static void main(String[] args) {
String a = "ABCD";
String b = a.toLowerCase();
b.replace('a', 'd');
b.replace('b', 'c');
System.out.println(b);
}
}
B. dccd
C. accd
D. abcd
D. abcd
15. What is output of below code?
public class Test {
public static void main(String[] args) {
System.out.println("Hello");
main(args);
}
}
A. Compiler Errorpublic static void main(String[] args) {
System.out.println("Hello");
main(args);
}
}
B. StackOverflowError Exception
C. Hello
D. Display Hello Infinite Times
B. StackOverflowError Exception
16. What is output of below code?
public class Test {
public static void main(String[] args) {
StringBuffer s = new StringBuffer("Hello");
System.out.print(s.length() + " ");
System.out.print(s.capacity());
}
}
A. 5 5public static void main(String[] args) {
StringBuffer s = new StringBuffer("Hello");
System.out.print(s.length() + " ");
System.out.print(s.capacity());
}
}
B. 5 10
C. 5 16
D. 5 21
D. 5 21
17. What is output of bellow code?
public class Test {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = new String("Hello");
s2 = s2.intern();
System.out.println(s1 == s2 ? "s1 == s2" : "s1 != s2");
}
}
A. s1 == s2public static void main(String[] args) {
String s1 = "Hello";
String s2 = new String("Hello");
s2 = s2.intern();
System.out.println(s1 == s2 ? "s1 == s2" : "s1 != s2");
}
}
B. s1 != s2
C. Compiler Error
D. Runtime Error
A. s1 == s2
18. What is output of bellow code?
public class Test {
public static void main(String[] args) {
String str = "Hello";
System.out.print(str.substring(2) + " ");
System.out.print(str.substring(2, 4));
}
}
A. llo llpublic static void main(String[] args) {
String str = "Hello";
System.out.print(str.substring(2) + " ");
System.out.print(str.substring(2, 4));
}
}
B. llo llo
C. Hello Hello
D. ello ll
A. llo ll
19. What is output of bellow code?
public class Test {
public static void main (String [] args){
String str = "9876567342",str1 = "I am from Bangalore Karnataka";
System.out.print(str.matches("[\\d]{8,12}") + " ");
System.out.print(str1.startsWith("am") + " ");
System.out.print(str1.endsWith("taka") + " ");
System.out.print(str1.contains("galor") + " ");
}
}
A. false false true truepublic static void main (String [] args){
String str = "9876567342",str1 = "I am from Bangalore Karnataka";
System.out.print(str.matches("[\\d]{8,12}") + " ");
System.out.print(str1.startsWith("am") + " ");
System.out.print(str1.endsWith("taka") + " ");
System.out.print(str1.contains("galor") + " ");
}
}
B. true false true true
C. true false true false
D. false false false false
B. true false true true
No comments:
Post a Comment