class HappyGarbage01 {      

Loading

Practice Garbage Collections –

class HappyGarbage01 {      
public static void main(String args[]) {
HappyGarbage01 h = new HappyGarbage01();
h.methodA(); /* Line 6 */
}
Object methodA() {
Object obj1 = new Object();
Object [] obj2 = new Object[1];
obj2[0] = obj1;
obj1 = null;
return obj2[0];
}
}

Where will be the most chance of the garbage collector being invoked?

/* Missing statements ? */ 
pub

Loading

Practice Operators and Assignments –

/* Missing statements ? */ 
public class NewTreeSet extends java.util.TreeSet {
public static void main(String [] args) {
java.util.TreeSet t = new java.util.TreeSet();
t.clear();
}
public void clear() {
TreeMap m = new TreeMap();
m.clear();
}
}

which two statements, added independently at beginning of the program, allow the code to compile?

  1. No statement is required
  2. import java.util.*;

     

  3. import.java.util.Tree*;

     

  4. import java.util.TreeSet;

     

  5. import java.util.TreeMap;

     

import java.awt.*; 
class Ticke

Loading

Practice Operators and Assignments –

import java.awt.*; 
class Ticker extends Component {
public static void main (String [] args) {
Ticker t = new Ticker();
/* Missing Statements ? */
}
}

which two of the following statements, inserted independently, could legally be inserted into missing section of this code?

  1. boolean test = (Component instanceof t);
  2. boolean test = (t instanceof Ticker);
  3. boolean test = t.instanceof(Ticker);
  4. boolean test = (t instanceof Component);

Which of the following are true statements?

  1. The 

Loading

Practice Operators and Assignments –

Which of the following are true statements?

  1. The Iterator interface declares only three methods: hasNextnext and remove.
  2. The ListIterator interface extends both the List and Iterator interfaces.
  3. The ListIterator interface provides forward and backward iteration capabilities.
  4. The ListIterator interface provides the ability to modify the List during iteration.
  5. The ListIterator interface provides the ability to determine its position in the List.

What will be the output of the program?


			  		

Loading

Practice Language Fundamentals –

What will be the output of the program?

import java.util.*;  
class H {
public static void main (String[] args) {
Object x = new Vector().elements();
System.out.print((x instanceof Enumeration)+",");
System.out.print((x instanceof Iterator)+",");
System.out.print(x instanceof ListIterator);
}
}

 

What will be the output of the program?


			  		

Loading

Practice Operators and Assignments –

What will be the output of the program?

import java.util.*;  
class I {
public static void main (String[] args) {
Object i = new ArrayList().iterator();
System.out.print((i instanceof List)+",");
System.out.print((i instanceof Iterator)+",");
System.out.print(i instanceof ListIterator);
}
}

 

Suppose that you would like to create an instance of a new 

Loading

Practice Operators and Assignments –

Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?

Which class does not override the equals() and&n

Loading

Practice Operators and Assignments –

Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?

What will be the output of the program?


			  		

Loading

Practice Operators and Assignments –

What will be the output of the program?

String d = "bookkeeper"; 
d.substring(1,7);
d = "w" + d;
d.append("woo"); /* Line 4 */
System.out.println(d);

 

Which statement is true for the class java.util.ArrayList<

Loading

Practice Declarations and Access Control –

Which statement is true for the class java.util.ArrayList?

public class Test {
}

Loading

Practice Objects and Collections –

public class Test {
}

What is the prototype of the default constructor?