Important Questions for Object-Oriented Programming Exam
Q: 1. Define Programming Paradigm and its types.
A: Programming Paradigm refers to a style or way of programming. Types include:
- Imperative (e.g., C, Python)
- Declarative (e.g., SQL)
- Object-Oriented (e.g., Java, C++)
- Functional (e.g., Haskell, Scala).
Q: 2. Differentiate between POP and OOP.
A: Procedure-Oriented Programming (POP):
- Focuses on procedures/functions.
- Does not support data hiding.
Object-Oriented Programming (OOP):
- Focuses on objects containing data and methods.
- Supports abstraction, encapsulation, inheritance, and polymorphism.
Q: 3. What are the important OOP fundamentals?
A: OOP fundamentals include:
- **Class**: A blueprint for creating objects.
- **Object**: An instance of a class.
- **Abstraction**: Hiding unnecessary details.
- **Encapsulation**: Binding data and methods together.
- **Inheritance**: Sharing features between classes.
- **Polymorphism**: Using one interface in different ways.
Q: 4. Explain the basics of Java programming environment.
A: - JDK: Java Development Kit, used to write and compile Java programs.
- JRE: Java Runtime Environment, executes Java programs.
- JVM: Java Virtual Machine, platform-independent runtime engine.
- Bytecode: Intermediate code executed by JVM.
Q: 5. What is the difference between String and StringBuffer?
A: - **String**: Immutable, modifications create new objects.
- **StringBuffer**: Mutable, modifications happen in-place.
Q: 6. Explain the types of constructors in Java.
A: - Default Constructor: No parameters.
- Parameterized Constructor: Accepts arguments.
- Copy Constructor: Copies data from one object to another.
- Private Constructor: Used for Singleton design pattern.
- Constructor Overloading: Multiple constructors in a class.
Q: 7. What are the types of inheritance in Java?
A: Inheritance allows a class to inherit properties and methods from another class. Types:
- Single
- Multilevel
- Hierarchical
- Hybrid (with Interfaces).
Note: Java does not support multiple inheritance directly due to ambiguity.
Q: 8. Differentiate between abstract class and interface.
A: - Abstract Class: Can have both concrete and abstract methods.
- Interface: Only abstract methods (prior to Java 8), default and static methods allowed since Java 8.
- Use 'extends' for abstract classes and 'implements' for interfaces.
Q: 9. Explain how to create and use a package in Java.
A: - Create a package: Use 'package <name>' at the top of the file.
- Compile: Use 'javac -d . <filename>.java'.
- Import: Use 'import <package_name>.*'.
Example:
```java
package mypack;
public class MyClass {
public void display() {
[Link]("Hello from MyClass");
```