Java_OOPS_Viva_Questions_with_Answers
Java_OOPS_Viva_Questions_with_Answers
Java_OOPS_Viva_Questions_with_Answers
Answer: OOP is a programming paradigm based on the concept of objects, which contain data
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
Answer: A class is a blueprint for creating objects, and an object is an instance of a class.
Answer: Inheritance allows a class to acquire properties and methods of another class. Example:
class B extends A.
Answer: Overloading occurs within the same class with different method signatures. Overriding
Answer: Encapsulation is the bundling of data and methods. Java achieves it by using private
variables and public getter/setter methods.
Answer: Abstraction hides implementation details and shows only the essential features. Example:
Answer: 'super' is used to refer to the immediate parent class's methods or constructors.
Answer: Constructors initialize an object when it is created. They have the same name as the class.
13. Can you differentiate between default constructor and parameterized constructor?
Answer: It prevents modification. Final variables: constants, final methods: cannot be overridden,
Answer: It ensures proper flow of the program using try, catch, and finally blocks, encapsulating
error handling.
16. What are static methods and variables in Java?
Answer: Static methods/variables belong to the class rather than any specific object.
Answer: Access modifiers (public, private, protected, default) control the visibility of members.
Answer: Inner classes are defined within another class. Types: static, non-static, local, and
anonymous.
22. What is the difference between deep copy and shallow copy?
Answer: Shallow copy: Copies references only. Deep copy: Copies all object fields.
25. What is the difference between '== operator' and 'equals() method'?
Answer: A class that allows only one instance to be created. Example: using a private constructor.
Answer: Annotations provide metadata about the program, e.g., @Override, @Deprecated.
Answer: No, static methods belong to the class and are not overridden but hidden.
Answer: Classes that encapsulate primitive data types (e.g., Integer, Double).
Answer: When a static method in a subclass has the same name and signature as in the parent
class.