Encapsulation helps in hiding the internal state of an object, ensuring that only authorized methods can access or modify the data. This prevents unauthorized access to sensitive information, promoting security.
What type of class is an Interface in OOP?
A Abstract
B Final
C Static
D Concrete
An interface is an abstract class in OOP. It only declares method signatures and does not provide the method implementations. A class implementing the interface must provide the actual method definitions.
Which principle allows a derived class to reuse code from its base class?
A Polymorphism
B Inheritance
C Abstraction
D Encapsulation
Inheritance allows a subclass to inherit fields and methods from a superclass. This promotes code reusability, reduces redundancy, and allows for easier maintenance and modification of code.
What is a Constructor used for in a class?
A Method overloading
B Memory allocation
C Exception handling
D Object initialization
A constructor is a special method in OOP used to initialize new objects. It is called automatically when an object is instantiated and sets up initial values for the object’s attributes.
Which of these is an example of Method Overriding in OOP?
A Same name, same parameters
B Same name, different parameters
C Same method in different class
D Same name, different behavior
Method overriding happens when a subclass provides its own implementation of a method that is already defined in its superclass with the same name and parameters, enhancing flexibility.
What does Polymorphism enable in OOP?
A Data hiding
B Method overriding
C Dynamic method invocation
D Object creation
Polymorphism allows the invocation of methods based on the object type at runtime, rather than the reference type. This is known as dynamic method dispatch and allows more flexible and reusable code.
Which access modifier allows a class to be accessed only within its package?
A Public
B Protected
C Default
D Private
In Java, if no access modifier is specified, the default access level is applied, which means the class or method is only accessible within its own package, restricting access from other packages.
What is the main goal of Abstraction?
A Class construction
B Simplifying complex systems
C Multiple inheritance
D Code reuse
Abstraction is used to hide the complex implementation details of an object and expose only the essential features. This simplifies the system and allows for a higher level of interaction with the object.
What is the difference between static and dynamic binding?
A Compile-time vs runtime
B Class vs object
C Method vs constructor
D Data vs methods
Static binding occurs at compile time, where method calls are resolved based on the method signature. Dynamic binding happens at runtime, where the method to call is determined by the object type.
Which of the following is an example of Exception Handling?
A Object serialization
B Method overloading
C Interface implementation
D Try-Catch block
Exception handling is a mechanism used to handle runtime errors. The Try-Catch block in languages like Java allows the program to continue executing even if an exception occurs, by catching and handling the error.
What is the purpose of a Destructor in OOP?
A Return object to memory
B Manage inheritance
C Initialize object state
D Clean up resources
A destructor is used to release resources (like memory or file handles) when an object is no longer needed. It is automatically called when an object is destroyed or goes out of scope.
What is the purpose of Object Serialization?
A Data persistence
B Dynamic binding
C Method overloading
D Code execution
Object serialization is the process of converting an object into a byte stream, which can then be written to a file or transmitted over a network. This allows objects to be stored and restored, ensuring data persistence.
Which of the following is a design pattern used in OOP?
A Singleton
B Cloning
C Inheritance
D Memory management
The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance. It is used to control access to shared resources or objects.
Which of the following does Multithreading allow in OOP?
A Memory management
B Dynamic binding
C Concurrent execution
D Method overriding
Multithreading allows multiple threads to run concurrently within a program, enabling efficient use of CPU resources and improving performance, especially for tasks that can be executed in parallel.
What is UML used for in OOP?
A Data analysis
B Object serialization
C Visual representation of classes
D Code execution
UML (Unified Modeling Language) is used to visually represent the structure and behavior of a system. It helps in designing and planning software by illustrating how classes interact, their relationships, and other important components.