- Which of the following is true about Singleton pattern?
View Answer
Correct answer: D — All of the above
- 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 EduinqSingleton s1 = EduinqSingleton.getInstance(); 12 EduinqSingleton s2 = EduinqSingleton.getInstance(); 13 System.out.println(s1 == s2); 14 } 15 } View Answer
Correct answer: A — true
- Which of the following is true about Factory pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface EduinqProduct { void show(); } 2 class EduinqA implements EduinqProduct { public void show(){ System.out.println("Eduinq A"); } } 3 class EduinqFactory { 4 static EduinqProduct getProduct(String type) { 5 if(type.equals("A")) return new EduinqA(); 6 return null; 7 } 8 } 9 public class Test { 10 public static void main(String[] args) { 11 EduinqProduct p = EduinqFactory.getProduct("A"); 12 p.show(); 13 } 14 } View Answer
Correct answer: A — Eduinq A
- Which of the following is true about Builder pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class EduinqBuilder { 2 private String name; 3 EduinqBuilder setName(String name){ this.name=name; return this; } 4 Eduinq build(){ return new Eduinq(name); } 5 } 6 class Eduinq { 7 String name; 8 Eduinq(String name){ this.name=name; } 9 public String toString(){ return name; } 10 } 11 public class Test { 12 public static void main(String[] args) { 13 Eduinq e = new EduinqBuilder().setName("Eduinq Portal").build(); 14 System.out.println(e); 15 } 16 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about Observer pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.*; 2 class EduinqSubject extends Observable { 3 void change(){ setChanged(); notifyObservers("Eduinq Update"); } 4 } 5 class EduinqObserver implements Observer { 6 public void update(Observable o, Object arg){ System.out.println(arg); } 7 } 8 public class Test { 9 public static void main(String[] args) { 10 EduinqSubject s = new EduinqSubject(); 11 s.addObserver(new EduinqObserver()); 12 s.change(); 13 } 14 } View Answer
Correct answer: A — Eduinq Update
- Which of the following is true about Strategy pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface EduinqStrategy { void execute(); } 2 class EduinqA implements EduinqStrategy { public void execute(){ System.out.println("Eduinq Strategy A"); } } 3 class Context { 4 private EduinqStrategy strategy; 5 Context(EduinqStrategy s){ this.strategy=s; } 6 void run(){ strategy.execute(); } 7 } 8 public class Test { 9 public static void main(String[] args) { 10 Context c = new Context(new EduinqA()); 11 c.run(); 12 } 13 } View Answer
Correct answer: A — Eduinq Strategy A
- Which of the following is true about Dependency Injection (DI)?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class EduinqService { void serve(){ System.out.println("Eduinq Service"); } } 2 class Client { 3 private EduinqService service; 4 Client(EduinqService s){ this.service=s; } 5 void doWork(){ service.serve(); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 Client c = new Client(new EduinqService()); 10 c.doWork(); 11 } 12 } View Answer
Correct answer: A — Eduinq Service
- Which of the following is true about Eager Singleton?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class EduinqSingleton { 2 private static final 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 Double Checked Locking Singleton?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Abstract Factory pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface EduinqButton { void click(); } 2 class WinButton implements EduinqButton { public void click(){ System.out.println("Eduinq Windows Button"); } } 3 class MacButton implements EduinqButton { public void click(){ System.out.println("Eduinq Mac Button"); } } 4 interface EduinqFactory { EduinqButton createButton(); } 5 class WinFactory implements EduinqFactory { public EduinqButton createButton(){ return new WinButton(); } } 6 public class Test { 7 public static void main(String[] args) { 8 EduinqFactory f = new WinFactory(); 9 f.createButton().click(); 10 } 11 } View Answer
Correct answer: A — Eduinq Windows Button
- Which of the following is true about Immutable Builder objects?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Observer pattern in JavaFX?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import javafx.beans.property.*; 2 public class Test { 3 public static void main(String[] args) { 4 StringProperty sp = new SimpleStringProperty("Eduinq"); 5 sp.addListener((obs,oldVal,newVal)->System.out.println("Changed to "+newVal)); 6 sp.set("Portal"); 7 } 8 } View Answer
Correct answer: A — Changed to Portal
- Which of the following is true about Strategy pattern with lambdas?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface EduinqStrategy { void run(); } 2 public class Test { 3 public static void main(String[] args) { 4 EduinqStrategy s = () -> System.out.println("Eduinq Lambda Strategy"); 5 s.run(); 6 } 7 } View Answer
Correct answer: A — Eduinq Lambda Strategy
- Which of the following is true about Dependency Injection annotations in Spring?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import org.springframework.beans.factory.annotation.*; 2 import org.springframework.stereotype.*; 3 @Component 4 class EduinqService { public String serve(){ return "Eduinq Spring Service"; } } 5 @Component 6 class Client { 7 @Autowired EduinqService service; 8 public void work(){ System.out.println(service.serve()); } 9 } View Answer
Correct answer: A — Eduinq Spring Service
- Which of the following is true about SOLID principles?
View Answer
Correct answer: D — All of the above
- Which of the following is true about DRY principle?
View Answer
Correct answer: D — All of the above
- Which of the following is true about KISS principle?
View Answer
Correct answer: D — All of the above
- Which of the following is true about modular design?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Adapter pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface EduinqTarget { void request(); } 2 class Legacy { void specificRequest(){ System.out.println("Eduinq Legacy"); } } 3 class Adapter implements EduinqTarget { 4 private Legacy legacy = new Legacy(); 5 public void request(){ legacy.specificRequest(); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 EduinqTarget t = new Adapter(); 10 t.request(); 11 } 12 } View Answer
Correct answer: A — Eduinq Legacy
- Which of the following is true about Proxy pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Decorator pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Composite pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Command pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Template Method pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about State pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Chain of Responsibility?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Mediator pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Memento pattern?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 private String state; 3 public void setState(String s){ state=s; } 4 public String getState(){ return state; } 5 public Memento save(){ return new Memento(state); } 6 public void restore(Memento m){ state=m.getState(); } 7 static class Memento { 8 private String state; 9 Memento(String s){ state=s; } 10 String getState(){ return state; } 11 } 12 } 13 public class Test { 14 public static void main(String[] args) { 15 Eduinq e = new Eduinq(); 16 e.setState("Eduinq Portal"); 17 Eduinq.Memento m = e.save(); 18 e.setState("Changed"); 19 e.restore(m); 20 System.out.println(e.getState()); 21 } 22 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about Flyweight pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Interpreter pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Visitor pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Bridge pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Facade pattern?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Best Practices in Singleton?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Best Practices in Factory?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Best Practices in Builder?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Best Practices in Observer?
View Answer
Correct answer: D — All of the above
- Which of the following is true about Best Practices in Dependency Injection?
View Answer
Correct answer: D — All of the above