Oops Interview Questions
Oops Interview Questions
Textual Example:
o Class: A Car class defines attributes like make, model, and speed, and methods
like accelerate() and brake().
o Object: An object of the Car class could be car1, where make = "Toyota", model
= "Camry", and speed = 60.
9. What is an access modifier in OOP and what are the different types?
Answer:
Access modifiers define the visibility and accessibility of classes, methods, variables.
The main types are:
o Public: Accessible from any class.
Textual Example:
o Public: A name variable declared as public in a class can be accessed directly
from any class.
o Private: A balance variable in a BankAccount class is private and can’t be
accessed directly outside the class.
o Protected: A protected method in a class can be accessed within the class and
subclasses, but not from outside the class.
Textual Example:
o Final Variable: final int MAX_SPEED = 120; makes MAX_SPEED a constant.