Java Unit – I : Part A – 16 Mark Answers
1. What is Object-Oriented Programming?
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects that
contain data (attributes) and methods (functions). It helps in organizing software into reusable, modular
components.
Key Concepts:
• Class – Blueprint for objects
• Object – Instance of class
• Encapsulation – Binding data & methods
• Inheritance – Reusing properties
• Polymorphism – One interface, many forms
• Abstraction – Hiding internal details
Advantages:
• Reusability, Modularity, Easy Maintenance, Security, Real-world modeling.
--------------------------------------------------
2. Outline the structure of a Java program.
Components:
• Package declaration
• Import statements
• Class definition
• Main method
• Program logic/statements
Example:
package sample;
import [Link].*;
class Demo {
public static void main(String[] args){
[Link]("Hello Java");
}
}
--------------------------------------------------
3. What is JavaDoc Comments?
JavaDoc comments are special multi-line comments used to generate documentation automatically in
HTML format. They begin with /** and end with */.
Tags:
• @param – Method parameter
• @return – Return type
• @author
• @version
• @throws
Example:
/**
* Adds two numbers
* @param a First number
* @param b Second number
* @return Sum of a and b
*/
int add(int a, int b) {
return a + b;
}
--------------------------------------------------
4. How to define a two-dimensional array in Java?
Declaration:
int[][] arr;
Creation:
arr = new int[3][4];
Initialization:
int[][] matrix = {
{1,2,3},
{4,5,6},
{7,8,9}
};
Accessing:
matrix[0][2]; // 3
--------------------------------------------------
5. Outline to define classes in Java.
Class Structure:
class ClassName {
// variables
// constructors
// methods
}
Example:
class Student {
int id;
String name;
Student(int i, String n){
id = i;
name = n;
}
void display(){
[Link](id + " " + name);
}
}