1 . Given:
[code]
AnInterface is an interface.
AnAdapter0 is a non-abstract, non-final class with a zero argument constructor.
An Adapterl is a non-abstract, non-final class without a zero argument constructor, but with a
constructor that takes one int argument.
[/code]
Which two construct an anonymous inner class?
Choose the two below:
- AnAdapter1 aa = new AnAdapter1 () {}
- AnAdapter0 aa = new AnAdapter0 () {}
- AnAdapter0 aa = new AnAdapter0 (5) {}
- AnAdapter1 aa = new AnAdapter1 (5) {}
- AnInterface ai = new Anlnterface (5)) {
2 . What will be the output?
[code lang=”java”]
class A {
public String to String() {
return ?4?;
}
}
class B extends A {
public String toString() {
return super.toString() + ?3?;
}
}
public class Test {
public static void main (String[] args) {
System.out.printIn(new B());
}
}
[/code]
Choose the one below:
- Compilation succeeds and 4 is printed
- Compilation ????? is printed
- An error on line 9 cause compilation to fail
- An error on line 14 cause compilation to fail
- Compilation succeeds but an exception is thrown at line 9
3 . What will be the output?
[code lang=”java”]
public class Method Over {
public void set Var (int a, int b, float c) {
}
}
[/code]
Choose the two below:
- private void set Var(int a, float c, int b) {}
- protected void set Var(int a, int b, float c) {}
- public int set Var(int a, float c, int b) {return a}
- public int set Var(int a, int b, float c) {return a}
- protected float set Var(int a, int b, float c) {return c}
4 . What will be the output?
[code lang=”java”]
class A {
public byte file Number () {
return l;
}
}
Class B extends A {
public short getNumber() {
return 2;
}
public short getNumber() {
B b = new B();
System.out.printIn(b.getNumber());
}
}
[/code]
Choose the one below:
- Compilation succeeds and l is printed
- Compilation succeeds and 2 printed
- An error at line 8 cause compilation to fail
- An error at line 14 cause complication to fail
- Complication succeeds but an exception is thrown at line 14
5 . What will be the output?
[code lang=”java”]
public class Foo {
public static void main(String[] args) {
StringBuffer a = new StringBuffer(?A?);
StrinbBuffer b = new StringBuffer(?B?);
operate (a, b);
System.out.printIn(a + ?,? + b)
}
static void operate (StringBuffer x, StringBuffer y) {
y.append(x);
y = x;
}
}
[/code]
Choose the one below:
- The code compiles and prints ?A,B?
- The code compiles and prints ?A,BA?
- The code compiles and prints ?AB,B?
- The code compiles and prints ?AB,AB?
- The code compiles and prints ?BA,BA?
- The code does not compile because ?+? cannot be overloaded for StringBuffer
6 . What will be the output?
[code lang=”java”]
public class X {
private static int a
public static void main (String [] args) {
modify (a)
System.out.printIn(a) {
}
public static void modify (int a) {
a++;
}
}
[/code]
Choose the one below:
- The program runs and prints ?0?
- The program runs and prints ?1?
- The program runs but aborts with an exception
- An error ?possible undefined variable? at line 5 cause compilation to fail
- An error ?possible undefined variable? at line 10 cause compilation to fail
7 . What will be the output?
[code lang=”java”]
public class Test {
private static int j = 0;
public static Boolean method B (int k) {
j + = k;
return true
}
public static void method A (int i) {
Boolean b;
b = I < 10 | method b (4)
b = I < 10 || method b(8)
}
public static void main (String args []) {
method A (0);
System.out.printIn(i);
}
}
[/code]
Choose the one below:
- The program prints ?0?
- The program prints ?4?
- The program prints ?8?
- The program prints ?12?
- The code does not compile
8 . Which two are equivalent?
- 16 > 4
- 16 / 2
- 16 * 4
- 16 >> 2
- 16 / 22
- 16 >>> 2
9 . What will be the output?
[code lang=”java”]
public class X {
public static void main (String [] args) {
byte b = 1277;
byte c = 126;
byte d = b + C;
}
}
[/code]
Choose the one below:
- Compilation succeed and d take the value 253
- Line 5 contains an error that prevents compilation
- Line 5 throws an exception indicating ?out of range?
- Line 3 and 4 contain errors that prevent compilation
- The compilation succeed and d takes the value of 1
10 . What will be the output?
[code lang=”java”]
int index = 1;
int[]foo = new int [3];
int bar = foo [index];
int baz = bar + index;
[/code]
Choose the one below:
- baz has a value of 0
- baz has a value of 1
- baz has the value of 2
- An exception is thrown
- The code will not compile
Answers
1 : 2 & 4 is correct.
2 : 2 is correct.
3 : 1 & 3 is correct.
4 : 3 is correct.
5 : 2 is correct.
6 : 1 is correct.
7 : 2 is correct.
8 : 4 & 6 is correct.
9 : 2 is correct.
10 : 2 is correct.
Leave a Reply