ProgrammingHardGATE CS · Product-company placement
An interface Machine declares print(), scan() and fax(). A SimplePrinter class implements it and has to make scan() and fax() throw UnsupportedOperationException. Which principle is violated?
- A. Open/Closed Principle
- B. Dependency Inversion Principle
- C. Single Responsibility Principle
- D. Interface Segregation Principle
Correct answer: D. Interface Segregation Principle
Clients should not be forced to depend on methods they do not use. Splitting Machine into Printer, Scanner and Fax interfaces lets SimplePrinter implement only what it supports.
More OOP with C++ and Java questions
- A GUI toolkit must create a matching Button, Checkbox and Window for either a Windows or a Mac theme, guaranteeing that all widgets come…
- In C++11 and later, which statement about this 'Meyers singleton' is correct? cpp Logger& instance() { static Logger log; return log; }
- How many of these are resolved at COMPILE time in C++? (i) Which function body a call to a non-virtual member function through a…
- What is printed? java String b = "java"; String a = "ja" + "va"; String c = "ja"; String d = c + "va"; final String e = "ja"; String f = e…
- What is printed? java class A { void f(Object o) { System.out.print("AO "); } void f(String s) { System.out.print("AS "); } } class B…
- What is printed? java class P { String n = "P"; String get() { return n; } } class C extends P { String n = "C"; String get() { return n…