Group A — Short answer Questions (1 mark)

Q1Define Object-Oriented Programming (OOP) and contrast it with Procedural Programming.

OOP is a paradigm based on 'objects' containing data and methods. Unlike Procedural Programming, which focuses on functions and top-down logic, OOP emphasizes data security (encapsulation) and reusability.

Q2What is an Object and what is a Class in Java/C++?

A Class is a blueprint or template that defines variables and methods. An Object is a runtime instance of a class containing actual values.

Q3Define Encapsulation and Data Hiding.

Encapsulation is wrapping data (variables) and code (methods) into a single unit. Data Hiding restricts direct access to internal data, usually achieved via private access modifiers.

Q4What is Abstraction? How is it implemented in Java?

Abstraction hides complex implementation details and shows only the essential features. In Java, it is implemented using abstract classes and interfaces.

Q5Define Inheritance and state its primary benefit.

Inheritance is a mechanism where a new class inherits properties and behaviors of an existing class. Its primary benefit is code reusability.

Q6What is Polymorphism? Differentiate Compile-time and Run-time Polymorphism.

Polymorphism allows entities to take multiple forms. Compile-time (method overloading) is resolved during compilation, while Run-time (method overriding) is resolved dynamically at execution.

Q7What is a Constructor? List its characteristics.

A Constructor is a special method used to initialize objects. Characteristics: it has the same name as the class, has no return type, and is called automatically during object creation.

Q8What is constructor overloading?

Constructor overloading is defining multiple constructors in a class with different parameter lists (different number or types of arguments) to initialize objects in various ways.

Q9What is the 'this' keyword used for in Java?

The 'this' keyword is a reference variable in Java that refers to the current object. It is used to resolve naming conflicts between instance variables and parameters.

Q10Define the 'super' keyword and its uses.

The 'super' keyword refers to the immediate parent class object. It is used to call parent class constructors, methods, and access hidden parent fields.

Q11What is the difference between Method Overloading and Method Overriding?

Overloading occurs in the same class with same method name but different parameters (compile-time). Overriding occurs in a subclass with the exact same signature as the parent method (run-time).

Q12Why does Java not support multiple inheritance with classes?

Java doesn't support multiple inheritance with classes to avoid the Diamond Problem (ambiguity when multiple parent classes have a method with the same signature).

Q13How do Interfaces help achieve multiple inheritance in Java?

A class can implement multiple interfaces simultaneously because interfaces only contain abstract methods (prior to Java 8), so there is no ambiguity in method implementation.

Q14What is the difference between an Abstract Class and an Interface?

An Abstract Class can have both abstract and concrete methods with state, while an Interface historically has only abstract methods and static final constants, and a class can implement multiple interfaces.

Q15Define access modifiers in Java (public, private, protected, default).

  • public: Accessible everywhere.
  • private: Accessible only within the same class.
  • protected: Accessible within the package and subclasses.
  • default: Accessible only within the same package.

Q16What is a static variable and a static method?

A static variable belongs to the class rather than instances, shared among all objects. A static method can be called without creating an object and can only directly access static data.

Q17What is the purpose of the 'final' keyword with variables, methods, and classes?

  • Variables: Creates a constant.
  • Methods: Prevents overriding.
  • Classes: Prevents inheritance.

Q18Explain Garbage Collection in Java and the role of finalize() / System.gc().

Garbage Collection automatically frees memory by destroying unreachable objects. System.gc() requests a garbage collection run, and finalize() is a method called just before an object is destroyed for cleanup.

Q19What is a Package in Java? How is it created and imported?

A Package is a namespace that organizes a set of related classes and interfaces. It is created using the package keyword at the top of the file and imported using the import keyword.

Q20Define Exception Handling. What are checked and unchecked exceptions?

Exception Handling manages runtime errors to maintain normal flow. Checked exceptions are verified at compile-time (e.g., IOException), while Unchecked exceptions occur at runtime (e.g., NullPointerException).

Q21What is the purpose of try, catch, finally, throw, and throws keywords?

  • try: Wraps risky code.
  • catch: Handles exceptions.
  • finally: Executes crucial cleanup code.
  • throw: Manually triggers an exception.
  • throws: Declares exceptions a method might throw.

Q22What is a user-defined custom exception?

A user-defined exception is a custom exception class created by a developer (usually by extending the Exception or RuntimeException class) to handle application-specific errors.

Q23Define Multithreading. What is a Thread?

Multithreading is the concurrent execution of multiple threads to maximize CPU utilization. A Thread is the smallest lightweight unit of processing or execution within a program.

Q24Differentiate between Process-based and Thread-based multitasking.

Process-based involves heavyweight independent programs with separate memory spaces. Thread-based involves lightweight concurrent paths of execution that share the same memory space within one process.

Q25How can a thread be created in Java (Thread class vs Runnable interface)?

A thread can be created either by extending the Thread class and overriding run(), or by implementing the Runnable interface and passing it to a Thread constructor.

Q26What are thread priorities in Java?

Thread priorities dictate the order in which threads are scheduled. In Java, priorities range from 1 (MIN_PRIORITY) to 10 (MAX_PRIORITY), with 5 being the default (NORM_PRIORITY).

Q27Define Thread Synchronization and the 'synchronized' keyword.

Thread Synchronization restricts multiple threads from accessing shared resources concurrently to prevent data inconsistency. The synchronized keyword locks the object or class during execution.

Q28What is Inter-Thread Communication? Mention wait(), notify(), and notifyAll().

Inter-Thread Communication allows synchronized threads to communicate. wait() pauses a thread, while notify() and notifyAll() wake up one or all waiting threads on that monitor.

Q29What is Deadlock in multithreading?

Deadlock is a situation where two or more threads are blocked forever, each waiting for a lock held by the other, bringing the program to a halt.

Q30What is the String class in Java? Why are Strings immutable?

The String class represents a sequence of characters. Strings are immutable (unchangeable) for security, synchronization, caching, and to optimize the String Pool memory management.

Q31Differentiate between String, StringBuilder, and StringBuffer.

String is immutable. StringBuilder is mutable and not thread-safe (faster). StringBuffer is mutable and thread-safe (synchronized, slower).

Q32What is a Wrapper Class? Define Autoboxing and Unboxing.

A Wrapper Class encapsulates a primitive type into an object. Autoboxing is automatic conversion of primitive to wrapper object; Unboxing is the reverse conversion.

Q33What is the Java Collections Framework (JCF)?

The JCF is a unified architecture providing ready-to-use classes and interfaces (like List, Set, Map) for storing, manipulating, and searching groups of objects.

Q34Differentiate between List, Set, and Map interfaces.

  • List: Ordered collection that allows duplicates.
  • Set: Unordered collection with no duplicates.
  • Map: Collection of Key-Value pairs, keys must be unique.

Q35What is the difference between ArrayList and LinkedList?

ArrayList uses a dynamic array (better for searching/random access). LinkedList uses a doubly linked list (better for frequent insertions/deletions).

Q36What is HashMap and how does it store key-value pairs?

HashMap is a Map implementation that stores key-value pairs using a hash table. It uses a hashing algorithm on keys to compute indices for bucketing values.

Q37Define Generics in Java and state their main advantage.

Generics allow types (classes and interfaces) to be parameters when defining classes, interfaces, and methods. Their main advantage is compile-time type safety and avoiding explicit casting.

Q38What is File I/O in Java? Differentiate Byte Streams and Character Streams.

File I/O handles reading and writing to files. Byte Streams (e.g., FileInputStream) read/write 8-bit bytes (for binary data). Character Streams (e.g., FileReader) read/write 16-bit Unicode characters.

Q39What is Serialization and Deserialization in Java?

Serialization converts an object's state into a byte stream for saving or networking. Deserialization reconstructs the object from the byte stream.

Q40Define the 'transient' keyword in Java Serialization.

The transient keyword marks a variable so that it is ignored during serialization; its value will not be saved or transmitted.

Q41What is a Lambda Expression in Java 8?

A Lambda Expression provides a concise syntax to write anonymous methods, typically used to implement the single abstract method of a functional interface.

Q42Define Functional Interface and give two standard examples.

A Functional Interface has exactly one abstract method. Examples include Runnable and Callable (or Predicate and Function from java.util.function).

Q43What is the Stream API in Java 8?

The Stream API provides a functional and declarative approach to process collections of objects (filtering, mapping, reducing) allowing for easy parallel execution.

Q44Define Design Patterns. Differentiate Creational, Structural, and Behavioral patterns.

Design Patterns are proven solutions to common software design problems. Creational deals with object creation, Structural with object composition, and Behavioral with object communication.

Q45What is the Singleton Design Pattern?

The Singleton pattern ensures that a class has only one single instance throughout the application lifecycle and provides a global point of access to it.

Q46What is the Factory Method Pattern?

The Factory Method is a creational pattern that defines an interface for creating objects, but lets subclasses decide which class to instantiate.

Q47Define the SOLID principles of Object-Oriented Design.

SOLID stands for Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion—five principles for maintainable object-oriented design.

Q48What is Unified Modeling Language (UML)?

UML is a standard visual modeling language used in software engineering to document, specify, construct, and visualize the artifacts of a software system.

Q49What is the difference between Association, Aggregation, and Composition?

Association is a general relationship. Aggregation is a "has-a" relationship (weak ownership). Composition is a strict "part-of" relationship (strong ownership, part dies with whole).

Q50What is a Class Diagram in UML?

A Class Diagram is a structural UML diagram that shows the system's static structure by detailing classes, their attributes, methods, and relationships.

Q51Define Virtual Functions and Pure Virtual Functions in C++.

A Virtual Function allows derived classes to override a method for runtime polymorphism. A Pure Virtual Function (assigned = 0) forces derived classes to implement it, making the base class abstract.

Q52What is the Friend Function / Friend Class in C++?

A Friend Function/Class in C++ is granted access to the private and protected members of the class in which it is declared as a friend.