0% found this document useful (0 votes)
6 views6 pages

Java_Exam_Answer_Sheet

The document is a Java exam paper consisting of three groups of questions: very short answer type, short answer type, and long answer type. It covers various Java concepts such as memory management, object-oriented principles, exception handling, and GUI frameworks. The paper includes definitions, examples, and comparisons of key Java features and constructs.

Uploaded by

tuhinakhanam557
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
6 views6 pages

Java_Exam_Answer_Sheet

The document is a Java exam paper consisting of three groups of questions: very short answer type, short answer type, and long answer type. It covers various Java concepts such as memory management, object-oriented principles, exception handling, and GUI frameworks. The paper includes definitions, examples, and comparisons of key Java features and constructs.

Uploaded by

tuhinakhanam557
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

Java Exam Paper - Answer Sheet

Group-A (Very Short Answer Type Questions)

Answer any ten of the following:

1. Heap memory

2. Java Virtual Machine (JVM)

3. C) public

4. True

5. B) FORTRAN - Object-Oriented Language

6. True

7. A) int number[]

8. B) Independent

9. setColor()

10. B) Garbage collection is present

11. True

12. D) System dependent

Group-B (Short Answer Type Questions)

Answer any three of the following:

1. Qualified association represents a relationship where a qualifier is used to distinguish between

objects of the associated class.

Example:

class Library {

Map<String, Book> books; // String (ISBN) acts as a qualifier


}

2. An object is an instance of a class containing state (attributes) and behavior (methods).

Java is object-oriented because it is based on principles like encapsulation, inheritance, and

polymorphism.

Differences:

- Procedural: Focus on functions; no data encapsulation.

- Object-Oriented: Focus on objects; encapsulates data and functions together.

3. The static keyword makes a variable or method belong to the class rather than any instance of

the class.

Example:

class Example {

static int count = 0; // Static variable

static void display() { // Static method

System.out.println("Count: " + count);

4. Dynamic method dispatch allows a method to be called based on the runtime type of the object.

Example:

class Parent {

void show() { System.out.println("Parent class"); }

class Child extends Parent {

void show() { System.out.println("Child class"); }

}
public class Main {

public static void main(String[] args) {

Parent obj = new Child(); // Runtime polymorphism

obj.show(); // Output: Child class

5. AWT (Abstract Window Toolkit) is a Java framework for building GUI applications.

Event Listener is an interface that handles events, such as button clicks or mouse movements, in

GUI applications.

Group-C (Long Answer Type Questions)

Answer any three of the following:

1. Differences between the following:

i) throw and throws clause

- throw: Used to explicitly throw an exception.

- throws: Declares exceptions a method might throw.

ii) final and finally

- final: Used to declare constants, prevent method overriding, or inheritance.

- finally: Executes cleanup code in a try-catch block.

iii) Abstract classes and Interfaces

- Abstract class: Can have concrete methods; supports inheritance.

- Interface: Pure abstraction; supports multiple inheritance.


2. Write short notes on the following:

i) Link and Association

- Link: A single connection between objects.

- Association: A broader relationship between classes.

ii) Thread Life-Cycle

- States: New, Runnable, Running, Blocked, Terminated.

iii) Encapsulation

- Encapsulation: Bundling data and methods into a single unit (class).

3. Write short notes on the following:

i) Dynamic method dispatch

- Allows method resolution during runtime based on the object type.

ii) Dynamic binding

- Links method calls to method definitions at runtime.

iii) Encapsulation

- Restricts access to class members using access modifiers like private.

4. Create a package and write a Java file with four methods for four basic arithmetic operations.

ArithmeticOperations.java:

package operations;

public class ArithmeticOperations {

public int add(int a, int b) { return a + b; }

public int subtract(int a, int b) { return a - b; }


public int multiply(int a, int b) { return a * b; }

public double divide(int a, int b) { return a / (double)b; }

Main.java:

import operations.ArithmeticOperations;

public class Main {

public static void main(String[] args) {

ArithmeticOperations ao = new ArithmeticOperations();

System.out.println("Addition: " + ao.add(10, 5));

System.out.println("Subtraction: " + ao.subtract(10, 5));

System.out.println("Multiplication: " + ao.multiply(10, 5));

System.out.println("Division: " + ao.divide(10, 5));

5. What are exceptions? Explain user-defined and system-defined exceptions.

- System-defined exceptions: Predefined in Java (e.g., NullPointerException, ArithmeticException).

- User-defined exceptions: Custom exceptions created by the programmer.

Example:

class MyException extends Exception {

public MyException(String message) {

super(message);

public class Main {

public static void main(String[] args) {


try {

throw new MyException("Custom Exception");

} catch (MyException e) {

System.out.println(e.getMessage());

a) this and super keywords

- this: Refers to the current object instance.

- super: Refers to the parent class.

b) Difference between = operator and .equals() method

- =: Compares references of two objects.

- .equals(): Compares content of two objects.

You might also like