OOP_Java_I_Q2_to_Q5_Detailed_Answers
OOP_Java_I_Q2_to_Q5_Detailed_Answers
[4 × 2 = 8]
Answer: A constructor is called automatically at the time of object creation. It is used to initialize the object. For example,
when we write: MyClass obj = new MyClass(); the constructor of MyClass is invoked.
Answer: Command line arguments are the arguments passed to the program when it is executed from the command
line. They are stored in the String array parameter of the main method:
Answer: A Frame is a top-level window with a title and a border used in Java AWT. It is used to create GUI applications.
Method Overriding:
- Occurs in subclass.
Answer:
interface Shape {
void area();
Triangle(double b, double h) {
base = b;
height = h;
Answer:
c) Write a Java Program to copy the contents from one file into another. Change case of all alphabets & replace
// Java logic:
Answer:
AWT:
- Heavyweight components
- Limited features
Swing:
- Lightweight components
- Rich UI components
b) Define user-defined exception ZeroNumberExc. Write a program to handle zero input and find sum of first &
Answer:
ZeroNumberExc(String msg) {
super(msg);
}
// Logic:
- Accept number
c) Write a Java program to store perfect numbers in array and display them.
Answer:
// Logic:
Answer:
Example:
b) Define a class Emp with member Eid and display() method. Inherit Emp into EmpName class with member
Answer:
class Emp {
int Eid;
void display() {
String Ename;
void display() {
super.display();