We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
JAVA ALL SETS SHORT ANSWERS MID-1
1. What is a Class and Object?
Ans) Class
• A class is a model or prototype defined with set of attributes and methods.
• It is a blue print for an object. • Collection of objects is called class. It is a logical entity. Object • Object is an instance of class. • Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.
2. Distinguish between Method Overloading and Method Overriding?
Ans) Method Overloading: Allows multiple methods with the same name but different parameter lists within the same class. It is an example of compile-time polymorphism. Method Overriding: Allows a subclass to provide a specific implementation for a method that is already defined in its superclass. It is an example of runtime polymorphism and is essential for achieving dynamic method dispatch in Java.
3. Explain about Exception its types.
Ans) An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions. Types: Checked exceptions (e.g., IOException), Unchecked exceptions (e.g.,NullPointerException), and Errors (e.g., OutOfMemoryError).
Ans) Classes that cannot be instantiated on their own and are meant to be sub-classed. They can contain abstract methods (without implementation) and concrete methods (with implementation). Abstract classes provide a base for other classes to build upon, ensuring a common interface or set of behaviors. ( OR) • An abstract class is a class that cannot be instantiated and is meant to be subclassed. It can contain abstract methods (without implementation) and concrete methods. Subclasses must implement abstract methods.
6. List all different Data type used in Java?
Ans) Primitive data types: byte, short, int, long, float, double, char, boolean. Non-primitive data types: Classes, Arrays, Strings, Interfaces.
7. Write about “Super” keyword?
Ans) The super keyword in Java is used to refer to the immediate parent class object. It is used to access superclass methods, constructors, and fields from a subclass.
8. List out various keywords used to handle exceptions in java
9. Distinguish between abstract class and interface?
Ans) Abstract class: Can have both abstract methods and concrete methods. A class can extend only one abstract class. Interface: Can only have abstract methods (prior to Java 8). A class can implement multiple interfaces.
10. List String Manipulation functions of Java String class?
Ans) Java is platform-independent due to the Java Virtual Machine (JVM). Java programs are compiled into bytecode, which can be executed on any system that has a JVM, regardless of the underlying platform.
12. Explain OOPs concepts.
Ans) Object-Oriented Programming (OOP) includes four main concepts: Encapsulation: Binding (or wrapping) code and data together into a single unit is known as encapsulation. Abstraction: Hiding internal details and showing functionality is known as abstraction. Inheritance: When one object acquires the properties and behaviors of parent object i.e., known as inheritance. Polymorphism: When one task is performed by different ways i.e. known as polymorphism. 13. What is a recursion? Ans) Recursion is the process in which a method calls itself to solve a problem. It is often used to solve problems that can be broken down into smaller, similar sub-problems. Recursion in java is a process in which a method calls itself continuously. A method in java that calls itself is called recursive method.
14. Distinguish between Exception and Error?
Ans) Exception: Indicates conditions that a program might want to catch (e.g., IOException). Error: Represents serious issues that are not typically caught by a program (e.g., OutOfMemoryError).
15. What is the need of garbage collector in java?
Ans) The garbage collector in Java automatically reclaims memory by removing objects that are no longer in use, thus preventing memory leaks and optimizing memory management.