Будь умным!


У вас вопросы?
У нас ответы:) SamZan.net

0 is printed D 1 is printed 2

Работа добавлена на сайт samzan.net:


1.Given the code. What is the result?

public class TrickyNum<X extends Object> {
    private X x;
    public TrickyNum(X x) {
        this.x = x;
    }
    private double getDouble() {
        return x.doubleValue();
    }
    public static void main(String args[]) {
        TrickyNum<Integer> a = new TrickyNum<Integer>(new Integer(1));
        System.out.print(a.getDouble());
    }
}

A) Compilation fails

B) An exception is thrown at runtime

C) "1.0" is printed

D) "1" is printed

2. Given the code. Select correct calls of methods. (Select all that apply)

import java.util.*;
class Empty {   
}
class Extended extends Empty {  
}
public class TryMe {    
        public static void doStuff1(List<Empty> list) {
                // some code
        }
        public static void doStuff2(List list) {        
                // some code
        }
        public static void doStuff3(List<? extends Empty> list) {
                // some code            
        }
        public static void main(String args[]) {
                List<Empty> list1 = new LinkedList<Empty>();
                List<Extended> list2 = new LinkedList<Extended>();
               // more code here
        }
}

  1.  doStuff1(list1);

B) doStuff2(list2);

C) doStuff2(list1);

D) doStuff3(list1);

E) doStuff3(list2);

F) doStuff1(list2);

3. Given the code. What is the result?

import java.util.Collections;
import java.util.LinkedList;
public class TryMe {
    public static void main(String args[]) {
        LinkedList<String> list = new LinkedList<String>();
        list.add("BbB1");
        list.add("bBb2");
        list.add("bbB3");
        list.add("BBb4");
        Collections.sort(list);
        for (String str : list) {
            System.out.print(str + ":");
        }
    }
}

  1.  "BbB1:bBb2:bbB3:BBb4:" is printed.
  2.  "BBb4:bbB3:bBb2:BbB1:" is printed.
  3.  "BBb4:BbB1:bBb2:bbB3:" is printed.
  4.  "bbB3:bBb2:BbB1:BBb4:" is printed
  5.  Compilation fails.
  6.  An exception is thrown at runtime.

4. Given the code. What is the result?

public class Cruiser implements Runnable {
    public static void main(String[] args) {
        Thread a = new Thread(new Cruiser());
        a.start();
        System.out.print("Begin");
        a.join();
        System.out.print("End");
    }
    public void run() {
        System.out.print("Run");
    }
}

  1.  Compilation fails.
  2.  An exception is thrown at runtime.
  3.  "BeginRunEnd" is printed.
  4.  "BeginEndRun" is printed.
  5.  "BeginEnd" is printed.

5. Which code, inserted at line labeled "//some code goes here", allows the class Test to be compiled?

class Util {
    public enum State{ACTIVE, DELETED, INACTIVE}
}
public class Test {     
    public static void main(String args[]) {
        //some code goes here       
    }
}

  1.  State state = State.INACTIVE;
  2.  State state = INACTIVE;
  3.  Util.State state = Util.State.INACTIVE;
  4.  State state = Util.INACTIVE;

6. What can directly access and change the value of the variable    roomNr?

package com.mycompany;
public class Hotel  {
    public int roomNr = 100;
}

  1.  Only the Hotel class.
  2.  Any class.
  3.  Any class in com.mycompany package.
  4.  Any class that extends Hotel.

7. Given the code. What is the result?

    public static void main(String args[]) {
        try {
            String arr[] = new String[10];
            arr = null;
            arr[0] = "one";
            System.out.print(arr[0]);
        } catch(NullPointerException nex) { 
            System.out.print("null pointer exception"); 
        } catch(Exception ex) {
            System.out.print("exception");
        }
    }

  1.  "one" is printed.
  2.  "exception" is printed.
  3.  "null pointer exception" is printed.
  4.  Compilation fails.

8. Given the code. What is the result?

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class HashTest {
    private String str;
    public HashTest(String str) {
        this.str = str;
    }

    public String toString() {
        return this.str;
    }
    public static void main(String args[]) {
        HashTest h1 = new HashTest("2");        
        String s1 = new String("1");        
       List<Object> list = new LinkedList<Object>();
        list.add(h1);
        list.add(s1);
         Collections.sort(list);
        for (Object o : list) {
            System.out.print(o + " ");
        }
    }
}

  1.  "2 1" is printed.
  2.  "1 2" is printed.
  3.  Compilation fails.
  4.  An exception is thrown at runtime.

9. Given the code. What is the result?

public class Hotel  {
    private static void book() {
        System.out.print("book");
    }
    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(1);
        book();
    }
}

  1.  Compilation fails.
  2.  An exception is thrown at runtime.
  3.  "book" is printed

10. Given the code. What is the result?

class Vehicle {
    public void printSound() {
        System.out.print("vehicle");
    }
}
class Car extends Vehicle {
    public void printSound() {
        System.out.print("car");
    }
}
class Bike extends Vehicle {
    public void printSound() {
        System.out.print("bike");
    }
}
public class Test {
    public static void main(String[] args) {
        Vehicle v = new Car();
        Bike b = (Bike) v;
        v.printSound();
        b.printSound();
    }   
}

  1.  Compilation fails.
  2.  An exception is thrown at runtime.
  3.  "vehiclecar" is printed.
  4.  "vehiclebike" is printed.
  5.  "carcar" is printed.
  6.  "bikebike" is printed

11. Given the code. What is true?

public class Room {
    public int roomNr;
    private Date beginDtm;
    private Date endDttm;
    public void book(int roomNr, Date beginDttm, Date endDttm) {
        this.roomNr = roomNr;
        this.beginDtm = beginDttm;
        this.endDttm = endDttm;
    }
}

  1.  The code demonstrates polymorphism.
  2.  The class is fully encapsulated.
  3.  The variable roomNr breaks encapsulation.
  4.  Variables beginDttm and endDttm break polymorphism.
  5.  The method book breaks encapsulation.

12. Given the code. What is the result?

1   public class TryMe {
2       Integer A;
3       int a;
4       public TryMe(int a) {
5           this.a = A + a;
6           System.out.print(this.a);
7       }
8       public static void main(String args[]) {        
9           Integer A = new Integer(1);
10          TryMe t = new TryMe(A);
11      }
12  }

  1.  The value "1" is printed
  2.  Compilation fails because of an error in line 5
  3.  A NullPointerException occurs at runtime
  4.  A NumberFormatException occurs at runtime
  5.  An IllegalStateExcepition occurs at runtime

13. Given the code. What is the result?

class Small {
    public Small() {
        System.out.print("a ");
    }
}
class Small2  extends Small {
    public Small2() {
        System.out.print("b ");
    }
}
class Small3 extends Small2 {
    public Small3() {
        System.out.print("c ");
    }
}
public class Test {     
    public static void main(String args[]) {
        new Small3();
    }
}

  1.  a
  2.  c
  3.  a b c
  4.  c b a
  5.  The code runs without output

14. Given the code. What is the result?

String test = "This is a test string";
String[] tokens = test.split("\\s");
System.out.println(tokens.length);  

  1.  0
  2.  5
  3.  21
  4.  Compilation fails
  5.  An exception is thrown at runtime

15. Given the code. What is the result?

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class TryMe {
    public static void main(String args[]) {
        List list = new LinkedList<String>();
        list.add("one");
        list.add("two");
        list.add("three");
        Collections.reverse(list);
        Iterator iter = list.iterator();
        for (Object o : iter) {
            System.out.print(o + " ");
        }
    }
}

  1.  "three two one " is printed
  2.  "one two three " is printed
  3.  Nothing is printed
  4.  Compilation fails
  5.  An exception is thrown at runtime

16. Given the code. What is the output?

public class Test {     
    int a = 10;
    public void doStuff(int a) {
        a += 1;
        System.out.println(++a);
    }
    public static void main(String args[]) {
        Test t = new Test();
        t.doStuff(3);
    }
}

  1.  4
  2.  5
  3.  12
  4.  11

17. Someone is writing a class MyKey, that will be used as a key in the java.util.HashMap. Which methods should be overriden to guarantee that MyKey works as HashMap  key? (Select all that apply)

  1.  public int has()
  2.  public int hashCode()
  3.  public boolean equals(MyKey)
  4.  public boolean equals(Object)
  5.  public int compareTo(Object)
  6.  public int compareTo(MyKey)

18. Which three statements concerning the use of the java.io.Serializable interface are true? (Choose three)

  1.  object from classes that use aggregation cannot be serialized
  2.  An object serialized on one JVM can be deserialized on a different JVM
  3.  The values in fields with the volatile modifier will not survive serialization and deserialization.
  4.  The values in field with the transient modifier will not survive serialization and deserialization
  5.  It is legal to serialize an object of a type that has a supertype that does not implement java.io.Serializable

19. Given the code. What is the result?

import java.util.HashSet;
public class HashTest {
    private String str;
    public HashTest(String str) {
        this.str = str;
    }   

    public int hashCode() {             
        return this.str.hashCode();
    }
    public boolean equals(Object obj) { 
        return this.str.equals(obj);
    }
    public static void main(String args[]) {
        HashTest h1 = new HashTest("1");
        HashTest h2 = new HashTest("1");
        String s1 = new String("2");
        String s2 = new String("2");
        HashSet<Object> hs = new HashSet<Object>();
        hs.add(h1);
        hs.add(h2);
        hs.add(s1);
        hs.add(s2);
        System.out.print(hs.size());
    }
}

  1.  "4" is printed
  2.  "3" is printed
  3.  "2" is printed
  4.  Compilation fails
  5.  An exception is thrown at runtime

20. Given the code. What is the result?

import java.io.*;
public class Hotel implements Serializable {
    private transient Room room = new Room();
    public static void main(String[] args) {
        Hotel h = new Hotel();
        try {
            FileOutputStream fos = new FileOutputStream("Hotel.dat");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(h);
            oos.close();
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}
class Room { }

  1.  Compilation fails
  2.  An exception is thrown at runtime
  3.  An instance of Hotel is serialized
  4.  An instance of Hotel and an instance of Room are both serialized

21. Given the code. What is the result?

import java.util.*;
public class TryMe {
    public static void main(String args[]) {
        Queue<String> q = new PriorityQueue<String>();
        q.add("3");
        q.add("1");
        q.add("2");
        System.out.print(q.poll() + " ");
        System.out.print(q.peek() + " ");
        System.out.print(q.peek());
    }
}

  1.  1 2 3
  2.  3 2 1
  3.  1 2 2
  4.  3 1 1
  5.  2 3 3
  6.  1 1 2

22. Given the code. What is the result?

    public static void main(String args[]) {
        String str = null;
        if (str.length() == 0) {
            System.out.print("1");
        } else if (str == null) {
            System.out.print("2");
        } else {
            System.out.print("3");
        }
    }

  1.  Compilation fails.
  2.  "1" is printed.
  3.  "2" is printed.
  4.  "2" is printed.
  5.  An exception is thrown at runtime.

23. What is the result?

 

public class Hotel {
    public static void book(short a) {
        System.out.print("short ");
    }
    public static void book(Short a) {
        System.out.print("SHORT ");
    }
    public static void book(Long a) {
        System.out.print("LONG ");
    }
    public static void main(String[] args) {
        short shortRoom = 1;
        int intRoom = 2;
        book(shortRoom);
        book(intRoom);
    }
}

  1.  SHORT LONG
  2.  short LONG
  3.  Compilation fails
  4.  An exception is thrown at runtime

24. Given the code. What is the result?

 

import java.util.Arrays;
public class HashTest {
    private String str;
    public HashTest(String str) {
        this.str = str;
    }

    public String toString() {
        return this.str;
    }
    public static void main(String args[]) {
        HashTest h1 = new HashTest("2");        
        String s1 = new String("1");        
        Object arr[] = new Object[2];
        arr[0] = h1;
        arr[1] = s1;
        Arrays.sort(arr);
        for (Object o : arr) {
            System.out.print(o + " ");
        }
    }
}

  1.  "2 1" is printed.
  2.  "1 2" is printed.
  3.  Compilation fails.
  4.  An exception is thrown at runtime.

25. Given the code. What is the result when this program is executed?

public class SuperHotel {
    static int x[];
    static {
        x[0] = 1;
    }
    public static void main(String args[]) {        
    }   
}

  1.  ArrayIndexOutOfBoundsException is thrown
  2.  ExceptionInInitializerError is thrown
  3.  IllegalStateException is thrown
  4.  StackOverflowException is thrown

26. A Java bean component has the following field:

private boolean done;

Which method declarations follow the JavaBean standards for getting/settings this field? (Choose 3)

  1.  public void setDone(boolean done)
  2.  public boolean setDone(boolean done)
  3.  private boolean setDone(boolean done)
  4.  public void setDone()
  5.  public boolean getDone()
  6.  public boolean isDone()
  7.  public boolean getDone(boolean done)
  8.  public void isDone()

27. Given the code. What is true about it? (Choose all that apply)

enum State{ACTIVE, INACTIVE, DELETED}

  1.  State.ACTIVE == State.ACTIVE is true
  2.  State.ACTIVE == State.INACTIVE is false
  3.  State.ACTIVE.equals(State.ACTIVE) is true
  4.  State.ACTIVE < State.INACTIVE is true

28. What is true about has-a and is-a relationships? (Choose two)

  1.  Instance variables can be used when creating a has-a relationship
  2.  Inheritance represents an is-a relationship
  3.  Inheritance represents a has-a relationship
  4.  Instances must be used when creating a has-a relationship

29. Given the code. What is the result?

public class SomeClass {
    private Integer value = 1;
   public Integer getValue() {
        return value;
    }
    public void changeVal(Integer value) {
        value = new Integer(3);
    }
    public static void main(String args[]) {
        Integer a = new Integer(2);
        SomeClass c = new SomeClass();
        c.changeVal(a);
        System.out.print(a);
    }
}

  1.  "1" is printed
  2.  "2" is printed
  3.  Compilation fails
  4.  An exception is thrown at runtime

30. Given the code. What is the result?

public class TryMe {
    public static void printB(String str) {
         System.out.print(Boolean.valueOf(str) ? "true" : "false"); 
    }
    public static void main(String args[]) {
        printB("tRuE");
        printB("false");
    }
}

  1.  "truefalse" is written
  2.  "falsefalse" is written
  3.  "truetrue" is written
  4.  Compilation fails
  5.  An exception is thrown at runtime

31. Give the code. What is the result?

class Hotel {
    public int bookings;
    public void book() {
        bookings++;
    }
}
public class SuperHotel extends Hotel {
    public void book() {
        bookings--;
    }
    public void book(int size) {
        book();
        super.book();
        bookings += size;
    }
    public static void main(String args[]) {
        SuperHotel hotel = new SuperHotel();
        hotel.book(2);
        System.out.print(hotel.bookings);
    }
}

  1.  Compilation fails
  2.  An exception is thrown at runtime
  3.  0
  4.  1
  5.  2
  6.  -1

32. Given the code. What is the result?

public class Cruiser implements Runnable {
    public void run() {
        System.out.print("go");
    }
    public static void main(String arg[]) {
        Thread t = new Thread(new Cruiser());
        t.run();
        t.run();
        t.start();
    }
}

  1.  Compilation fails
  2.  An exception is thrown at runtime
  3.  "go" is printed
  4.  "gogogo" is printed
  5.  "gogo" is printed

33. What is true? (Choose three)

  1.  A method with the same signature as a private final method in class Z can be implemented in a subclass of Z.
  2.  A final method in class Z can be abstract if and only if Z is abstract.
  3.  A protected method in class Z can be overriden by any subclass of Z.
  4.  A private static method can be called only within other static methods in class Z.
  5.  A non-static public final method in class Z can be overriden in any subclass of Z.
  6.  A public static method in class Z can be called by a subclass of Z without explicitly referencing the class Z.

34. The code below is executed by "java -Dmyprop=myprop Test". Which two, placed instead of "//some code goes here", will produce the output "myprop"? (Choose two)

public class Test { 
    public static void main(String args[]) {
        String prop = //some code goes here//
        System.out.print(prop);
    }
}

  1.  System.getEnv("myprop");
  2.  System.load("myprop");
  3.  System.property("myprop");
  4.  System.getProperty("myprop");
  5.  System.get("myprop");
  6.  System.getProperties().getProperty("myprop");

35. Given the code. What is the output?

1.  public static void main(String args[]) {
2.      Object myObj = new String[]{"one", "two", "three"};{
3.          
for (String s : (String[])myObj) System.out.print(s + ".");
4.      }
5.  }

  1.  one.two.three.
  2.  Compilation fails because of an error at line 2
  3.  Compilation fails because of an error at line 3
  4.  An exception is thrown at runtime

36. Give a piece of code. What is true?

    public void waitForSomething() {
        SomeClass o = new SomeClass();
        synchronized (o) {
            o.wait();
            o.notify();         
        }
    }

  1.  This code may throw an InterruptedException
  2.  This code may throw an IllegalStateException
  3.  This code may throw a TimeOutException
  4.  Reversing the ofrer of o.wait() and o.notify() will cause this method to complete normally

37.Given the code. What is the result?

    public static void main(String args[]) {
        String str = null;
        if (str == null) {
            System.out.print("1");
        } else (str.length() == 0) {
            System.out.print("2");
        } else {
            System.out.print("3");
        }
    }

  1.  Compilation fails.
  2.  "1" is printed.
  3.  "2" is printed.
  4.  "3" is printed.
  5.  An exception is thrown at runtime.

38. Given the code. What is the result after the class TryMe execution?

class A {
    public void doA() {
        B b = new B();
        b.dobB();
        System.out.print("doA");
    }
}
class B {
    public void dobB() {
        C c = new C();
        c.doC();
        System.out.print("doB");
    }
}
class C {
    public void doC() {
        if (true)
            throw new NullPointerException();
        System.out.print("doC");
    }
}
public class TryMe {
    public static void main(String args[]) {
        try {
            A a = new A();
            a.doA();
        } catch (Exception ex) {
            System.out.print("error");
        }
    }
}

  1.  "doCdoBdoA" is printed
  2.  "doAdoBdoC" is printed
  3.  "doBdoAerror" is printed
  4.  "error" is printed
  5.  nothing is printed

39. Which three will compile without exception? (Choose three)

  1.  private synchronized SomeClass a;
  2.  void book() { synchronized () {} }
  3.  public synchronized void book() {}
  4.  public synchronized(this) void book() {}
  5.  public void book() { synchronized(Cruiser.class) {} }
  6.  public void book() {synchronized(a){}}

40. Given the code. What is the result?

1.  public static void main(String args[]) {
2.      Object myObj = new String[]{"one", "two", "three"} {
3.          
for (String s : (String[])myObj) System.out.print(s + ".");
4.      }
5.  }

  1.  one.two.three.
  2.  Compilation fails because of an error at line 2
  3.  Compilation fails because of an error at line 3
  4.  An exception is thrown at runtime

41. What do you need to do to correct compilation errors? (Select two)

public class Creature {
    private int legCount;
    private int wingCount;
    public Creature(int legCount) {
        this.legCount = this.legCount;
        this.wingCount = 0;
    }
    public String toString() {
        return "legs=" + this.legCount + " wings=" + wingCount;
    }
}
public class Animal extends Creature {
    public Animal(int legCount) {
        this.wingCount = 0;
    }
}

  1.  insert a call to super() into Creature constructor.
  2.  insert a call to super() into Animal constructor.
  3.  insert a call to this() into Animal constructor.
  4.  insert a call to super(legCount) into Animal constructor.
  5.  change the wingCount variable in the class Creature to protected.
  6.  change the string "this.wingCount = 0" in the class Animal to "super.wingCount = 0"

42. Given the code. Which statements are true? (Select two)

public class Hotel {         
        public static void book() {
                //some code goes here
        }
        public void cancelBooking() {
                //some code goes here
        }       
}

  1.  Method book() can directly call method cancelBooking()
  2.  Method cancelBooking() can directly call method book()
  3.  Hotel.book() is a valid invocation of book()  
  4.  Hotel.cancelBooking() is a valid invocation of cancelBooking()

43. What is true about objects referenced by a, b, aa at the line labeled "// some code goes here"?

class A {
    private B b;
    public A() {
        this.b = new B(this);
    }
}
class B {
    private A a;
    public B(A a) {
        this.a = a;
    }
}
public class Test { 
    public static void main(String args[]) {
        A aa = new A();
        aa = null;
        // some code goes here
    }
}

  1.  The objects referenced by a and b are eligible for garbage collection.
  2.  None of these objects are eligible for garbage collection.
  3.  Only the object referenced by "a" is eligible for garbage collection.
  4.  Only the object referenced by "b" is eligible for garbage collection.
  5.  Only the object referenced by "aa" is eligible for garbage collection.

44. Give a piece of code. Which two are possible results? (Select two)

public class Cruiser {
    private int a = 0;
    public void foo() {
        Runnable r = new LittleCruiser();
        new Thread(r).start();
        new Thread(r).start();
    }
    public static void main(String arg[]) {
        Cruiser c = new Cruiser();
        c.foo();
    }
    public class LittleCruiser implements Runnable {
        public void run() {
            int current = 0;
            for (int i = 0; i < 4; i++) {
                current = a;
                System.out.print(current + ", ");
                a = current + 2;
            }
        }
    }
}

  1.  0, 2, 4, 0, 2, 4, 6, 6,
  2.  0, 2, 4, 6, 8, 10, 12, 14,
  3.  0, 2, 4, 6, 8, 10, 2, 4,
  4.  0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,
  5.  0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

45. Given the code. What is the result?

public class Test { 
    private static void doStuff(String str) {
        int var = 4;
        if (var == str.length()) {
            System.out.print(str.charAt(--var) + " ");
        }
        else {
            System.out.print(str.charAt(0) + " ");
        }
    }
    public static void main(String args[]) {
        doStuff("abcd");
        doStuff("efg");
        doStuff("hi");
    }
}

  1.  Compilation fails.
  2.  An exception is thrown at runtime.
  3.  d e h
  4.  d f i
  5.  c f i
  6.  c e h

46. When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exist as a method in only one of the two?

A)Closing the stream

B) flushing the stream

C) writing to the stream

D) marking a location in the stream

E) writing a line separator to the stream

47.Given the code. What is the result?

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.US);
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, 2009);
c.set(Calendar.MONTH, 6);
c.set(Calendar.DAY_OF_MONTH, 1);
String formattedDate = df.format(c.getTime());
System.out.println(formattedDate);

  1.  July 1, 2009
  2.  June 1, 2009
  3.  Compilation fails
  4.  An exception is thrown at runtime

48.Given:

d is a valid, non-null java.util.Date object
df is a valid, non-null java.text.DateFormat object set to the current locale.


What outputs the current locale's country name and the appropriate version of date?

  1.  Locale l = Locale.getDefault();
    System.out.println(l.getDisplayCountry() + " " + df.format(d));
  2.  Locale l = Locale.getLocale();
    System.out.println(l.getDisplayCountry());
  3.  Locale l = Locale.getLocale();
    System.out.println(l.getDisplayCountry() + " " + df.setDateFormat(d));
  4.  Locale l = Locale.getDefault();
    System.out.println(l.getDisplayCountry() + " " + df.setDateFormat(d));

49.Given the code. What is the result?

public class EmptyStringsTest {
    public static boolean isEmpty(String s) {
        return (s == null | s.length() == 0);
    }
    public static void main(String args[]) {
        if (isEmpty(null)) {
            System.out.print("empty ");
        } else {
            System.out.print("not_empty ");
        }
    }
}

  1.  "empty" is printed
  2.  "not_empty" is printed
  3.  Compilation fails
  4.  An exception is thrown at runtime

50.Given the code. What is the result?

1.      int i = 10;
2.      while (i++ <= 10) {
3.          i++;
4.      }
5.      System.out.print(i);

  1.  10
  2.  11
  3.  12
  4.  13
  5.  Line 5 will be never reached

51.Given the code below. This code is run by "java Test 1 2 3 4". What is the result?

public class Test { 
    public static void main(String args[]) {
        for (int i = 1; i < args.length; i++) {
            System.out.print(i + " ");
        }
    }
}

  1.  Compilation fails
  2.  An exception is thrown at runtime
  3.  1 2 3
  4.  1 2
  5.  2 3

52.Given the code. Which line of code marks the earliest point that an object referenced by myInt becomes a candidate for garbage collection?

1   public void doStuff() {
2       Integer arr[] = new Integer[5];
3       for (int i = 0; i < arr.length; i++) {
4           Integer myInt = new Integer(i);
5           arr[i] = myInt;
6       }
7       System.out.println("end");
8   }

  1.  Line 4
  2.  Line 5
  3.  Line 6
  4.  Line 7

53. Given two classes defined in two different files. What is required at line marked "//some code goes here" to process the method doStuff() of a class A?

// The first file
package pack1;
public class ClassA {
    public static void doStuff() {
        System.out.println("doStuff");
    }
}

// The second file
package pack2;
public class ClassB {
    public static void main(String args[]) {
        //some code goes here
    }
}

  1.  ClassA.doStuff();
  2.  pack1.ClassA.doStuff();
  3.  doStuff();
  4.  It is impossible to use the method doStuff() in the class B.
  5.  import pack1.A.*; doStuff();

54. Given the code. What is the result if NullPointerException occurs at line 2?

1.      try {
2.          //some code goes here
3.      }
4.      catch (NullPointerException ne) {
5.          System.out.print("1 ");
6.      }
7.      catch (RuntimeException re) {
8.          System.out.print("2 ");
9.      }
10.     finally {
11.         System.out.print("3");
12.     }

A) 1

B) 3

C) 1 3

D) 2 3

E) 1 2 3

F) 3 1

55. Given the code. What is the result?

class Vehicle {
    public void printSound() {
        System.out.print("vehicle");
    }
}
class Car extends Vehicle {
    public void printSound() {
        System.out.print("car");
    }
}
class Bike extends Vehicle {
    public void printSound() {
        System.out.print("bike");
    }
}
public class Test {
    public static void main(String[] args) {
        Vehicle v = new Car();
        Car c = (Car) v;
        v.printSound();
        c.printSound();
    }   
}

  1.  Compilation fails
  2.  An exception is thrown at runtime
  3.  "vehiclecar" is printed
  4.  "vehiclebike" is printed
  5.  "carcar" is printed
  6.  "bikebike" is printed

56. Given the code. What is the result?

public class Hotel  {
    private static void book() {
        System.out.print("book");
    }
    public static void main(String[] args) {
        Thread.sleep(1);
        book();
    }
}

  1.  Compilation fails
  2.  An exception is thrown at runtime
  3.  "book" is printed
  4.  The code executes normally, but nothing is printed

57. Given the code. What is the result?

public class TrickyNum<X extends Object> {
    private X x;
    public TrickyNum(X x) {
        this.x = x;
    }
    private double getDouble() {
        return ((Double) x).doubleValue();
    }
    public static void main(String args[]) {
        TrickyNum<Integer> a = new TrickyNum<Integer>(new Integer(1));
        System.out.print(a.getDouble());
    }
}

  1.  Compilation fails
  2.  An exception is thrown at runtime
  3.  "1.0" is printed
  4.  "1" is printed

58. Given the code. What is the result?

String test = "This is a test string";
String[] tokens = test.split("\s");
System.out.println(tokens.length);

  1.  0
  2.  5
  3.  21
  4.  Compilation fails
  5.  An exception is thrown at runtime

59. Given the code. What is the result?

import java.io.*;
public class Hotel implements Serializable {
    private Room room = new Room();
    public static void main(String[] args) {
        Hotel h = new Hotel();
        try {
            FileOutputStream fos = new FileOutputStream("Hotel.dat");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(h);
            oos.close();
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}
class Room implements Serializable {}

  1.  Compilation fails
  2.  An exception is thrown at runtime
  3.  An instance of Hotel is serialized
  4.  An instance of Hotel and an instance of Room are both serialized

60. Given the code. What is the result?

    public static void main(String args[]) {
                String str = "null";
                if (str == null) {
                        System.out.print("1");
                } else if (str.length() == 0) {
                        System.out.print("2");
                } else {
                        System.out.print("3");
                }
        }

  1.  Compilation fails
  2.  "1" is printed
  3.  "2" is printed
  4.  "3" is printed
  5.  An exception is thrown at runtime




1. Особливості нарахування митного тарифу в залежності від виду мита.html
2. Геополитики.html
3. Логистические концепции
4. РЕФЕРАТ дисертації на здобуття наукового ступеня кандидата хімічних наук КИЇВ ~7 Дисер
5. Путь к Любви отрывки Уступки Когда вы впервые слышите слово уступка то возможно оно ассоц
6. Лекція 910 Метод спостереження в соціальнопедагогічних досліджень
7. 6977000000 Разраб
8. Расчёт трансформаторов
9. задание и выскочите из аудитории с воплем
10. географических факторов водосборов; построения зависимостей между годичными стоковыми характеристиками
11. Организация агрохимического обслуживания в УОХ Краснодарское города Краснодара
12. Некоммерческие организации
13. . Принять к сведению Отчет о деятельности Думы Ростовского муниципального района в 2013 году Приложение
14. тематичного моделювання т
15. Реферат- Северо-Восточный Китай
16. Реферат- Антиинфляционная политика государства
17. РЕФЕРАТ ПО ДИСЦИПЛИНЕ ГЕОЛОГИЯ Карст и карстовые процессы
18. Эх если бы я знал все это с самого начала часто с огорчением замечают PRспециалисты
19.  Наблюдение является одним из наиболее часто используемых в психологии исследовательских методов
20. Контрольна робота з дисципліни Міжнародний економічний аналіз студентки спеціальності Міжнародна ек