- Which of the following is true about Singleton pattern?
View Answer
Correct answer: D — All of the above
- In Java, which is the most thread safe way to implement Singleton?
View Answer
Correct answer: C — Enum Singleton
- What will be printed?
1 class EduinqSingleton { 2 private static EduinqSingleton instance = new EduinqSingleton(); 3 private EduinqSingleton(){} 4 public static EduinqSingleton getInstance(){ return instance; } 5 } 6 public class Test { 7 public static void main(String[] args) { 8 System.out.println(EduinqSingleton.getInstance()!=null); 9 } 10 } View Answer
Correct answer: A — true
- Which of the following is true about Factory pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a benefit of Factory pattern?
View Answer
Correct answer: C — Makes code tightly coupled
- What will be printed?
1 interface EduinqProduct { String getName(); } 2 class EduinqFactory { 3 static EduinqProduct create(){ return () -> "Eduinq Product"; } 4 } 5 public class Test { 6 public static void main(String[] args) { 7 System.out.println(EduinqFactory.create().getName()); 8 } 9 } View Answer
Correct answer: A — Eduinq Product
- Which of the following is true about Observer pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is a real world example of Observer pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.*; 2 class EduinqObserver implements Observer { 3 public void update(Observable o, Object arg){ 4 System.out.println("Eduinq Update: " + arg); 5 } 6 } 7 class EduinqSubject extends Observable { 8 void change(){ 9 setChanged(); 10 notifyObservers("Changed"); 11 } 12 } 13 public class Test { 14 public static void main(String[] args) { 15 EduinqSubject s = new EduinqSubject(); 16 s.addObserver(new EduinqObserver()); 17 s.change(); 18 } 19 } View Answer
Correct answer: A — Eduinq Update: Changed
- Which of the following is true about Strategy pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a benefit of Strategy pattern?
View Answer
Correct answer: C — Increases coupling between algorithms
- What will be printed?
1 interface EduinqStrategy { String execute(); } 2 class StrategyA implements EduinqStrategy { public String execute(){ return "A"; } } 3 class StrategyB implements EduinqStrategy { public String execute(){ return "B"; } } 4 public class Test { 5 public static void main(String[] args) { 6 EduinqStrategy s = new StrategyB(); 7 System.out.println(s.execute()); 8 } 9 } View Answer
Correct answer: B — B
- Which of the following is true about Builder pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a benefit of Builder pattern?
View Answer
Correct answer: C — Increases constructor complexity
- What will be printed?
1 class Eduinq { 2 private String name; 3 private Eduinq(String name){ this.name=name; } 4 static class Builder { 5 private String name; 6 Builder setName(String n){ name=n; return this; } 7 Eduinq build(){ return new Eduinq(name); } 8 } 9 public String toString(){ return "Eduinq " + name; } 10 } 11 public class Test { 12 public static void main(String[] args) { 13 Eduinq e = new Eduinq.Builder().setName("Portal").build(); 14 System.out.println(e); 15 } 16 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about Proxy pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is a real world example of Proxy pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface EduinqService { String serve(); } 2 class RealService implements EduinqService { public String serve(){ return "Real"; } } 3 class ProxyService implements EduinqService { 4 private RealService real = new RealService(); 5 public String serve(){ return "Proxy -> " + real.serve(); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 EduinqService s = new ProxyService(); 10 System.out.println(s.serve()); 11 } 12 } View Answer
Correct answer: A — Proxy -> Real
- Which of the following is true about combining patterns?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a creational pattern?
View Answer
Correct answer: C — Observer
- Which of the following is true about Abstract Factory pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a behavioral pattern?
View Answer
Correct answer: C — Proxy
- What will be printed?
1 class EduinqSingleton { 2 private static EduinqSingleton instance; 3 private EduinqSingleton(){} 4 public static EduinqSingleton getInstance(){ 5 if(instance==null) instance=new EduinqSingleton(); 6 return instance; 7 } 8 } 9 public class Test { 10 public static void main(String[] args) { 11 System.out.println(EduinqSingleton.getInstance()!=null); 12 } 13 } View Answer
Correct answer: A — true
- Which of the following is true about Factory Method vs Abstract Factory?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a creational pattern?
View Answer
Correct answer: C — Proxy
- Which of the following is true about Observer pitfalls?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Strategy runtime switching?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface EduinqStrategy { String run(); } 2 class StrategyX implements EduinqStrategy { public String run(){ return "X"; } } 3 class StrategyY implements EduinqStrategy { public String run(){ return "Y"; } } 4 public class Test { 5 public static void main(String[] args) { 6 EduinqStrategy s = new StrategyX(); 7 System.out.println(s.run()); 8 } 9 } View Answer
Correct answer: A — X
- Which of the following is true about Builder immutability?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a structural pattern?
View Answer
Correct answer: C — Strategy
- Which of the following is true about Proxy security use cases?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Singleton drawbacks?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Factory Method benefits?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Observer in Java?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Strategy pattern drawbacks?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class EduinqBuilder { 2 private String name; 3 EduinqBuilder setName(String n){ name=n; return this; } 4 String build(){ return "Eduinq " + name; } 5 } 6 public class Test { 7 public static void main(String[] args) { 8 System.out.println(new EduinqBuilder().setName("Design").build()); 9 } 10 } View Answer
Correct answer: A — Eduinq Design
- Which of the following is true about Proxy vs Decorator?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a benefit of Builder pattern?
View Answer
Correct answer: D — Increases coupling
- Which of the following is true about Singleton in multithreading?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Factory vs Builder?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Observer pattern in event systems?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a benefit of Proxy pattern?
View Answer
Correct answer: C — Simplifies object creation
- Which of the following is true about Strategy pattern in payment systems?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Builder pattern in Java?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Proxy pattern drawbacks?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface Eduinq { String get(); } 2 class Real implements Eduinq { public String get(){ return "Real"; } } 3 class Proxy implements Eduinq { 4 private Real r=new Real(); 5 public String get(){ return "Proxy->"+r.get(); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 System.out.println(new Proxy().get()); 10 } 11 } View Answer
Correct answer: A — Proxy->Real
- Which of the following is true about combining Builder + Factory?
View Answer
Correct answer: D — All of the above
- Which of the following is NOT a design pattern category?
View Answer
Correct answer: D — Functional
- Which of the following is true about Singleton alternatives?
View Answer
Correct answer: D — All of the above
- Which of the following is true about design patterns overall?
View Answer
Correct answer: D — All of the above