1. What is OOPS?
Answer:
OOPS stands for Object-Oriented Programming System.
It is a programming paradigm where the software design is based on objects, which represent real-world entities.
Each object is an instance of a class and contains state (data) and behavior (methods).
2. What are the basic concepts of OOPS?
Answer:
The four fundamental principles of OOPS are:
-
Abstraction
-
Encapsulation
-
Inheritance
-
Polymorphism
3. What is a Class?
Answer:
A class is a blueprint or template used to create objects.
It defines:
-
Properties (variables / fields)
-
Behaviors (methods)
Example:
4. What is an Object?
Answer:
An object is a runtime instance of a class.
It has:
-
State → variables
-
Behavior → methods
-
Identity → unique memory reference
5. What is Encapsulation?
Answer:
Encapsulation is the process of binding data and methods together and restricting direct access to object data.
It is achieved using access modifiers:
-
public -
protected -
default -
private
Example:
6. What is Polymorphism?
Answer:
Polymorphism means “many forms”.
It allows the same method to behave differently based on the object type.
Types:
-
Compile-time (Method Overloading)
-
Runtime (Method Overriding)
7. What is Inheritance?
Answer:
Inheritance allows one class to reuse properties and methods of another class.
Types:
-
Single Inheritance
-
Multilevel Inheritance
-
Hierarchical Inheritance
Java does not support multiple inheritance with classes but supports it using interfaces.
8. What are Manipulators?
Answer:
Manipulators are special functions used with stream operators (<<, >>) in C++ to format input/output.
Examples:
-
endl -
setw
⚠️ Not applicable in Java.
9. What is a Constructor?
Answer:
A constructor is a special method used to initialize an object.
Rules:
-
Same name as the class
-
No return type
-
Automatically invoked during object creation
10. What is a Destructor?
Answer:
A destructor releases resources when an object is destroyed.
⚠️ Java does not support destructors.
Garbage Collection handles memory cleanup.
11. What is an Inline Function?
Answer:
An inline function is expanded at compile time to reduce function call overhead.
⚠️ Java does not support inline functions explicitly (JIT compiler optimizes internally).
12. What is Function Overloading?
Answer:
Function overloading allows multiple methods with the same name but different:
-
Parameters
-
Data types
-
Number of arguments
Example:
13. What is a Virtual Function?
Answer:
A virtual function supports runtime polymorphism.
⚠️ In Java:
-
All non-static methods are virtual by default
-
Implemented using method overriding
14. What is a Friend Function?
Answer:
Friend functions allow access to private members of a class.
⚠️ Java does NOT support friend functions (encapsulation is strict).
15. What is Operator Overloading?
Answer:
Operator overloading allows operators to behave differently for different operands.
⚠️ Java does not support operator overloading
(Except + for String concatenation).
16. What is an Abstract Class?
Answer:
An abstract class:
-
Cannot be instantiated
-
Can contain abstract and non-abstract methods
17. What is a Ternary Operator?
Answer:
The ternary operator is a conditional operator:
18. What is the use of finalize() method?
Answer:
finalize() was used for cleanup before garbage collection.
⚠️ Deprecated in Java 9+
Not recommended for resource management.
19. What are the types of Arguments?
Answer:
-
Call by Value – Java supports this
-
Call by Reference – Not supported directly in Java
Java always passes object references by value.
20. What is the super keyword?
Answer:
super is used to:
-
Access parent class methods
-
Access parent constructor
-
Access hidden variables
21. What is Method Overriding?
Answer:
Method overriding allows a child class to provide its own implementation of a parent class method.
Rules:
-
Same method name
-
Same parameters
-
Same return type
22. What is an Interface?
Answer:
An interface contains:
-
Abstract methods
-
Default methods (Java 8+)
-
Static methods
Used to achieve multiple inheritance in Java.
23. What is Exception Handling?
Answer:
Exception handling manages runtime errors using:
-
try -
catch -
finally -
throw -
throws
24. What are Tokens?
Answer:
Tokens are the smallest units of a program.
Examples:
-
Keywords
-
Identifiers
-
Constants
-
Operators
-
Separators
25. Difference between Overloading and Overriding?
| Feature | Overloading | Overriding |
|---|---|---|
| Binding | Compile-time | Runtime |
| Parameters | Different | Same |
| Return Type | Can vary | Must match |
| Class | Same class | Parent-Child |
No comments:
Post a Comment