0% found this document useful (0 votes)
2 views

OOP_Java_I_Answers

The document covers various Java programming concepts including the Java compiler, wrapper classes, constructors, and exception handling. It explains the differences between AWT and Swing, provides examples of interfaces and user-defined exceptions, and discusses perfect numbers and inheritance. Additionally, it outlines GUI components and file operations in Java.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

OOP_Java_I_Answers

The document covers various Java programming concepts including the Java compiler, wrapper classes, constructors, and exception handling. It explains the differences between AWT and Swing, provides examples of interfaces and user-defined exceptions, and discusses perfect numbers and inheritance. Additionally, it outlines GUI components and file operations in Java.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Q1

a) javac is the Java compiler that converts Java source code into bytecode (.class files).

b) Two wrapper classes: Integer, Double.

c) 'implements' keyword is used when a class implements an interface.

d) Types of constructors: Default, Parameterized, Copy constructor.

e) Array is used to store multiple values in a single variable.

f) Two listeners: ActionListener, MouseListener.

g) Exception is an event that disrupts the normal flow of a program.

h) Syntax of endsWith(): string.endsWith("suffix")

i) Package is a namespace that organizes a set of related classes and interfaces.

j) 'new' operator is used to create objects in Java.

Q2

a) A constructor is called automatically when an object is created.

b) Command line arguments are passed to main() and stored in the String[] args array.

c) Frame is a top-level window with a title and border. Methods: setSize(), setVisible().

d) Overloading: same method name, different parameters. Overriding: same method, subclass modifies behavior.

e) Two access specifiers: public, private.

Q3

a) Interface and Class:

interface Shape { void area(); }

class Triangle implements Shape {

double b, h;

public void area() {

System.out.println("Area: " + (0.5 * b * h));

b) Swing GUI:
- Use JFrame for window

- Add JTextField for Roll No, Name, Percentage

- Add JButton for Display and Clear

- Display data in console on clicking Display

- Clear all fields on Clear

c) File Copy:

- Read input file character by character

- If char is digit, replace with '*'

- If letter, change case

- Write modified content to output file

Q4

a) AWT vs Swing:

AWT: Heavyweight, platform-dependent. Swing: Lightweight, platform-independent.

b) User-defined exception:

class ZeroNumberExc extends Exception {...}

If input is zero, throw exception. Else, extract and sum first and last digit.

c) Perfect numbers:

- Accept n numbers from user

- Check each number if perfect (sum of divisors equals number)

- Store and display perfect numbers

Q5

a) final keyword:

- final variable: cannot be changed

- final method: cannot be overridden

- final class: cannot be inherited

b) Inheritance example:

class Emp { int Eid; void display() {...} }


class EmpName extends Emp { String Ename; void display() { super.display(); ... } }

You might also like