UttaraMockTests FirstTest
UttaraMockTests FirstTest
!
Uttara InfoSolutions
www.uttarainfo.com
!
First Test Questions (40Q - 50 Mins)
!
1) What will be printed out if this code is run with the following command line?
!
java myprog good morning
!
public class myprog
{
public static void main(String argv[])
{
System.out.println(argv[2]);
}
}
1) myprog
2) good
3) morning
4) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
!
2) Which of the following are legal identifiers
!
1) 2variable
2) variable2
3) _whatavariable
4) _3_
5) $anothervar
6) #myvar
!
Options:
a) 1,2,3,4
b) 2,3,4,5
c) 3,4,5,6
d) 1,3,4,6
!
3) What will happen when you compile and run the following code?
}
!
}
public class B extends A{
public D getOBJ(){
System.out.println("class B - return D");
return new D();
}
}
!
public class Test {
!
public static void main(String... args) {
A a = new B();
a.getOBJ();
}
}
!
Options
A)Compile with error - Not allowed to override the return type of a method with a subtype
of the original type.
B)class A - return C
C)class B - return D
D) Runtime Exception
!
27)
Given:
5. class Atom {
6. Atom() { System.out.print("atom "); } 7. }
A. Compilation fails.
B. atom granite
C. An exception is thrown at runtime.
28)
Given:
11. abstract class Vehicle { public int speed() { return 0; }
12. class Car extends Vehicle { public int speed() { return 60; } 13. class RaceCar extends
Car { public int speed() { return 150; } ...
21. RaceCar racer = new RaceCar();
22. Car car = new RaceCar();
23. Vehicle vehicle = new RaceCar();
24. System.out.println(racer.speed() + ", " + car.speed()
25. + ", " + vehicle.speed());
What is the result?
A. 0, 0, 0
B. 150, 60, 0
C. Compilation fails.
29)
Given:
5. class Building { }
6. public class Barn extends Building { 7. public static void main(String[] args) { 8. Building
build1 = new Building();
9. Barn barn1 = new Barn();
10. Barn barn2 = (Barn) build1;
11. Object obj1 = (Object) build1;
12. String str1 = (String) build1;
13. Building build2 = (Building) barn1; 14. }
15. }
Which is true?
30)
Given:
10. interface Foo {}
11. class Alpha implements Foo {} 12. class Beta extends Alpha {} 13. class Delta extends
Beta {
14. public static void main( String[] args ) { 15. Beta x = new Beta();
16. // insert code here
17. }
18. }
Which code, inserted at line 16, will cause a java.lang.ClassCastException?
A. Alpha a = x;
B. Foo f = (Delta)x;
C. Foo f = (Alpha)x;
D. Beta b = (Beta)(Alpha)x;
31)
Given:
1. public class Boxer1{
2. Integer i;
3. int x;
4. public Boxer1(int y) {
5. x = i+y;
6. System.out.println(x);
7. }
8. public static void main(String[] args) { 9. new Boxer1(new Integer(4));
10. }
11. }
What is the result?
Given:
3. public class Batman {
4. int squares = 81;
5. public static void main(String[] args) {
6. new Batman().go();
7. }
8. void go() {
9. incr(++squares);
10. System.out.println(squares);
11. }
12. void incr(int squares) { squares += 10; }
13. }
What is the result?
A. 81 B. 82 C. 91 D. 92
33)
Given:
3. interface Animal { void makeNoise(); }
4. class Horse implements Animal {
5. Long weight = 1200L;
6. public void makeNoise() { System.out.println("whinny"); }
7. }
8. public class Icelandic extends Horse {
9. public void makeNoise() { System.out.println("vinny"); }
10. public static void main(String[] args) {
11. Icelandic i1 = new Icelandic();
12. Icelandic i2 = new Icelandic();
12. Icelandic i3 = new Icelandic();
13. i3 = i1; i1 = i2; i2 = null; i3 = i1;
14. }
15. }
When line 14 is reached, how many objects are eligible for the garbage collector?
A. 0
B. 1
C. 4
D. 3
34)
Given:
1. public class A {
2. public void doit() { 3. }
9. }
10. }
What is the result?
35)
Given:
11. public static void main(String[] args) { 12. for (int i = 0; i <= 10; i++) {
13. if (i > 6) break;
14. }
15. System.out.println(i);
16. }
What is the result?
A. 6
B. 7
C. 10
D. Compilation fails.
!
36)
13. }
20. b.foo();
21. }
22. }
What is the result?
A. Afoo Afoo
B. Afoo Bfoo
C. Bfoo Afoo
D. Bfoo Bfoo
40)
Given:
3. class Fish { }
4. class Perch extends Fish { }
6. class Bluegill { }
System.out.print("f-p ");
System.out.print("w-f ");
What is the result?
A. w-f
B. f-p w-f
C. w-f b-f
D. f-p w-f b-f