Newsletter:

(Quiz) Sun JAVA2 Certification Program Volume 1.1

Quiz: Sun JAVA2 Certification Program Volume 1.1

Question 1. Which of the following are valid declarations? Assume
java.util.*
is imported.
A. Vector<Map> v;
B.Set<String> s;
C.Map<String> m;
D.Map<String, String> m;
Answers: A, B, D. The angle-bracket notation is part of release 5.0’s generic collections.

Question 2. You can determine all the keys in a Map in which of the following ways?

A. By getting a Set object from the Map and iterating through it.
B. By iterating through the Iterator of the Map.
C. By enumerating through the Enumeration of the Map.
D. By getting a List from the Map and enumerating through the List.
E. You cannot determine the keys in a Map.
Answers A. A Map contains a Set, which is a list that does not allow duplicates. Once you acquire the Set you can iterate through the keys. 

Question 3. What keyword is used to prevent an object from being serialized? 
A.private
B.volatile
C.protected
D.transient
E.None of the above
Answers D. By placing the keyword transient before an object’s declaration, that value will not be included with the serialized data of the parent object.

Question 4. An abstract class can contain methods with declared bodies.
A.True
B.False
Answers A. Abstract classes can contain methods that are defined and methods that are not defined.

Question 5. Select the order of access modifiers from least restrictive to most restrictive.
A.public,private,protected, default
B.default,protected,private,public
C.public, default,protected,private
D.default,public,protected,private
E.public,protected, default,private
Answers E. The public access modifier means the element is available to all; protected lets those within the class, package, or subclass gain access to the element. The lack of a modifier, that is ,“default,” means that it is accessible only within the package. Finally, private is the most restrictive and provides access within the class only.

Question 6.Which access modifier allows you to access method calls in libraries not created in Java?
A public
B. static
C. native
D. transient
E. volatile
Answers C. The native modifier is an indicator to the Java Virtual Machine that the method actually lives in a library outside of Java. The System.loadLibrary() method is required to indicate which library contains the method.

Question 7. Which of the following statements are true? (Select all that apply.)
A. A final object’s data cannot be changed.
B. A final class can be subclassed.
C. A final method cannot be overloaded.
D. A final object cannot be reassigned a new address in memory.
E. None of the above.
Answers D. An object denoted as final can have its data changed; however, the address location is what is determined as unchangeable. The third statement is false because a final method means it cannot be overridden, and the second statement is false because a final class means it cannot be subclassed.

Question 8. The keyword extends refers to what type of relationship?
A. “is a”
B. “has a”
C. “was a”
D. “will be a”
E. None of the above
Answers A. The keyword extends is used when referring to another class. The extending class will have all access to all the available methods in the extended class, and the methods may be called as though they are defined in the extending class. If the extending class defines a method that exists in the extended class, that method is said to be overridden in the extending class. Because the extending class does not have to define any of the methods available in the extended class, it is said that the subclass X “is a” Y. 

Question 9. Which of the following keywords is used to invoke a method in the parent class?
A. this
B. super
C. final
D. static
Answers B. The super keyword is used to invoke a method or constructor in a parent class.

Question 10. Given the following code, what will be the outcome?
public class Funcs extends java.lang.Math {
public int add(int x, int y) {
return x + y;
}
public int sub(int x, int y) {
return x - y;
}
public static void main(String [] a) {

Funcs f = new Funcs();

System.out.println("" + f.add(1, 2));

}

}

A. The code compiles but does not output anything.
B. “3” is printed out to the console.
C. The code does not compile.
D. None of the above.
Answers C. The code does not compile because it extends the Math class, which has been declared as final. A class cannot extend a class that has been declared final. 

Courtesy:- http://r4r.co.in/