READ Free Dumps For Oracle- 1z0-804
Question ID 21441 | Which two properly implement a Singleton pattern?
|
Option A | class Singleton {
private static Singleton instance;
private Singleton () {}
public static synchronized Singleton getInstance() {
if (instance == null) {
instance = new Singleton ();
}
return instance;
}
}
|
Option B | class Singleton {
private static Singleton instance = new Singleton();
protected Singleton () {}
public static Singleton getInstance () {
return instance;
}
}
|
Option C | class Singleton {
Singleton () {}
private static class SingletonHolder {
private static final Singleton INSTANCE = new Singleton ();
}
public static Singleton getInstance () {
return SingletonHolder.INSTANCE;
}
}
|
Option D | enum Singleton {
INSTANCE;
}
|
Correct Answer | A,D |
Explanation Note: Java has several design patterns Singleton Pattern being the most commonly used. Java Singleton pattern belongs to the family of design patterns, that govern the instantiation process. This design pattern proposes that at any time there can only be one instance of a singleton (object) created by the JVM. The class's default constructor is made private, which prevents the direct instantiation of the object by others (Other Classes). A static modifier is applied to the instance method that returns the object as it then makes this method a class level method that can be accessed without creating an object. OPTION A == SHOW THE LAZY initialization WITHOUT DOUBLE CHECKED LOCKING TECHNIQUE ,BUT ITS CORRECT OPTION D == Serialzation and thraead-safety guaranteed and with couple of line of code enum Singleton pattern is best way to create Singleton in Java 5 world. AND THERE ARE 5 WAY TO CREATE SINGLETON CLASS IN JAVA 1>>LAZY LOADING (initialization) USING SYCHRONIZATION 2>>CLASS LOADING (initialization) USING private static final Singleton instance = new Singleton(); 3>>USING ENUM 4>>USING STATIC NESTED CLASS 5>>USING STATIC BLOCK AND MAKE CONSTRUCTOR PRIVATE IN ALL 5 WAY.
Question ID 21442 | Given:
import java.util.ArrayList;
import java.util.List;
interface Glommer { }
interface Plinkable { }
public class Flimmer implements Plinkable {
List<Tagget> t = new ArrayList<Tagget>();
}
class Flommer extends Flimmer {
String s = "hey";
}
class Tagget implements Glommer {
void doStuff() {
String s = "yo";
}
}
Which two statements concerning the OO concepts "IS-A" and "HAS-A" are true?
|
Option A | Flimmer is-a Glommer.
|
Option B | Flommer has-a String.
|
Option C | Tagget has-a Glommer.
|
Option D | Flimmer is-a ArrayList.
|
Option E | Tagget has-a doStuff()
|
Option F | Tagget is-a Glommer.
|
Correct Answer | B,F |
Explanation Explanation: B: The relationship modeled by composition is often referred to as the "has-a" relationship. Here Flommer hasa String. E: The has-a relationship has an encapsulation feature (like private or protected modifier used before each member field or method). Here Tagget has-a method doStuff() F: Tagget implements Glommer. Tagget is-a Glommer. Note: The has-a relationship has an encapsulation feature (like private or protected modifier used before each member field or method).