Did you finish learning oops concepts?
TEST your skills & check your level in OOPs concepts by answering these following fine blended object-oriented programming questions and boost it fast with OOP Concepts Booster.
Code Examples:
Q-1) What can be the issues if you delete a base class method if a subclass overrides it?
For example, in the below code snippet of the table’s left column, the subclass Son has inherited the Father class and uses the methods useHome() and useCar(). But, in the table’s right column, the Son class overrides and defines the method useCar(), and at the same time deletes this method from the base class Father.
class Father {
public void usehome() {
}
public void useCar() {
}
}
class Son extends Father {
}
class Father {
public void useHome() {
}
}
class Son extends Father {
public void useCar() {
}
}
Q-2) This Board class in its write method accepts a BlueMarker concrete class object. Can you identify the problems that can occur in real-time with this working code? Can you write this class better?
class Board {
public void write(BlueMarker m) {
m.color();
}
}
Q-3) This original version of the switch interface is distributed to many clients.
interface Switch {
void on();
void off();
}
How would you update the update the Switch interface with a newer version that contains a LED light setting specification too i.e. “void setLed();”, so that the existing client does not break?
Q-4) If an option occurs to choose between abstract class and an interface, then what is the best option and why? For example:
interface Charger {
void charge();
}
abstract class Charger {
abstract void charge();
}
Q-5) How does encapsulation provide security?
Q-6) How to achieve abstraction using an “interface” or an “abstract class”?
Q-7) If we can’t create an object of an abstract class, then what is its purpose? What can be the scenarios of uses?
Q-8) Are both the concepts of encapsulation and abstraction really related to hiding complexities?
Q-9) What are the multiple ways to reuse the code in OOP?
Q-10) How can inheritance break the client code, but composition cannot? Illustrate the scenario example of this.
If you find difficulty answering these object-oriented programming questions, I would recommend reading the OOP Concepts Booster. You would be able to answer these types of questions and get incredible command and confidence in oops quickly.