Group-A: Very Short Answer Type Questions
1. In which memory is a String stored when we create a string using the new operator?
- Heap memory.
2. ______ is an abstract machine. It is a specification that provides a runtime
environment in which Java bytecode can be executed.
- Java Virtual Machine (JVM).
3. Which of the following keywords are used to control access to a class Member?
- B) abstract.
4. An abstract class, which is declared with the "abstract" keyword, cannot be
instantiated. True or False?
- True.
5. Out of the following, which one is not correctly matched?
- B) FORTRAN - Object Oriented Language.
6. "A package is a collection of classes, interfaces, and sub-packages." The above
statement is true or false?
- True.
7. Which of the following statements is a valid array declaration?
- B) float average[].
8. Java virtual machine is ______.
- B) Independent.
9. Which method is used to set the graphics' current color to the specified color in the
graphics class?
- setColor(Color c).
10. Java is robust because ______.
- It is object-oriented, supports garbage collection, and has exception handling.
11. Consider the following 2 statements (S1 and S2):
- S1: C++ uses compiler only.
- S2: Java uses compiler and interpreter both.
Above statements are true or false?
- True.
12. What is the length of the application box made by the following Java program?
```java
import java.awt.*;
import java.applet.*;
public class myApplet extends Applet {
public void paint(Graphics g) {
g.drawString("A Simple Applet", 20, 20);
```
- C) 100.
Group-B: Short Answer Type Questions
2. What is qualified association? Describe with an example.
- Qualified association refers to a relationship between two classes where one class
qualifies the association by providing additional information, typically through an
attribute.
Example:
In a library system, the relationship between a "Library" and "Book" classes can be
qualified by the "ISBN number."
3. What is an object? Why is Java called an object-oriented language? Write the
difference between procedural-oriented programming and object-oriented
programming.
- Object: An object is an instance of a class containing attributes (data) and methods
(functions).
- Why Java is object-oriented: Java is called object-oriented because it follows OOP
principles like encapsulation, inheritance, polymorphism, and abstraction.
- Difference:
- Procedural: Focuses on procedures (functions).
- Object-Oriented: Focuses on objects (data + methods).
4. Explain the static keyword with suitable Java code.
- The `static` keyword is used to create class-level variables and methods that belong
to the class rather than any object.
Example:
```java
class Example {
static int count = 0; // static variable
static void display() { // static method
System.out.println("Count: " + count);
```
5. What is dynamic method dispatch in Java? Explain with an example.
- Dynamic method dispatch allows a superclass reference to call methods in a
subclass object during runtime (polymorphism).
Example:
```java
class Parent {
void display() { System.out.println("Parent"); }
class Child extends Parent {
void display() { System.out.println("Child"); }
Parent obj = new Child();
obj.display(); // Outputs "Child"
```
6. What is AWT? What is Event Listener?
- AWT (Abstract Window Toolkit): A Java package used to create GUI components like
buttons and windows.
- Event Listener: An interface in Java used to handle events like clicks or keypresses.
Example: `ActionListener`.
Group-C: Long Answer Type Questions
7. Discuss the differences between the following:
- throw vs throws clause:
- `throw`: Used to explicitly throw an exception.
- `throws`: Declares exceptions in a method signature.
- final vs finally:
- `final`: Keyword to make variables/constants or prevent inheritance.
- `finally`: Block executed after try-catch, regardless of exception.
- Abstract classes vs Interfaces:
- Abstract classes can have both abstract and concrete methods.
- Interfaces contain only abstract methods (before Java 8).
8. Write short notes on the following:
- Link and Association: A relationship between objects in two classes.
- Thread Life-Cycle: New → Runnable → Running → Blocked → Terminated.
- Abstraction: Hiding implementation details and showing only functionality.
9. Write short notes on the following:
- Dynamic Method Dispatch: Polymorphism mechanism (explained earlier).
- Dynamic Binding: Method resolution at runtime.
- Encapsulation: Bundling data and methods in a single unit (class).
10. Create a package and write Java files for basic arithmetic operations.
- Solution Outline: Create a package with methods for addition, subtraction,
multiplication, and division. Import and use them in another file.
11. (a) What are exceptions? Explain user-defined and system-defined exceptions with
examples.
- Exceptions are events that disrupt the normal program flow.
- System-defined: Handled by Java (e.g., `ArithmeticException`).
- User-defined: Custom exceptions created using `extends Exception`.
Example:
```java
class MyException extends Exception {
MyException(String msg) { super(msg); }
```
(b) Difference between `==` operator and `equals` method in String:
- `==` compares references (memory locations).
- `equals` compares the content.