INDEX
[Link] Program Date Signature
Create a Student class to demonstrate basic class
1 and object concepts.
Implement constructor overloading to initialize
2 objects in multiple ways.
Demonstrate inheritance using parent and child
3 classes.
Show runtime polymorphism using method
4 overriding.
5 Illustrate use of primitive data types and operators.
6 Perform searching in an array.
7 Implement method overloading.
8 Use this keyword to differentiate variables.
9 Demonstrate abstract class implementation.
10 Show use of final keyword.
11 Create and use a package.
12 Implement multiple inheritance using interfaces.
13 Handle exceptions using try-catch.
14 Create user-defined exception.
15 Demonstrate multithreading and file handling.
PROGRAM 1
Objective:
Create a Student class to demonstrate basic class and object concepts.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Student {
int rollNo;
String name;
void display() {
[Link]("Roll No: " + rollNo);
[Link]("Name: " + name);
}
public static void main(String[] args) {
Student s = new Student();
[Link] = 101;
[Link] = "Ashish";
[Link]();
}
}
Output:
PROGRAM 2
Objective:
Implement constructor overloading to initialize objects in multiple ways.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Box {
double l,w,h;
Box(){ l=w=h=1; }
Box(double l,double w,double h){
this.l=l; this.w=w; this.h=h;
}
double volume(){ return l*w*h; }
public static void main(String[] args){
Box b1=new Box();
Box b2=new Box(2,3,4);
[Link]([Link]());
[Link]([Link]());
}
}
Output:
PROGRAM 3
Objective:
Demonstrate inheritance using parent and child classes.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Animal{
void eat(){ [Link]("Eating"); }
}
class Dog extends Animal{
void bark(){ [Link]("Barking"); }
public static void main(String[] args){
Dog d=new Dog();
[Link](); [Link]();
}
}
Output:
PROGRAM 4
Objective:
Show runtime polymorphism using method overriding.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Shape{
void draw(){ [Link]("Shape"); }
}
class Circle extends Shape{
void draw(){ [Link]("Circle"); }
public static void main(String[] args){
Shape s=new Circle();
[Link]();
}
}
Output:
PROGRAM 5
Objective:
Illustrate use of primitive data types and operators.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Demo{
public static void main(String[] args){
int a=10,b=5;
[Link](a+b);
[Link](a*b);
}
}
Output:
PROGRAM 6
Objective:
Perform searching in an array.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Search{
public static void main(String[] args){
int arr[]={10,20,30};
int key=20;
for(int x:arr){
if(x==key){
[Link]("Found");
}
}
}
}
Output:
PROGRAM 7
Objective:
Implement method overloading.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Calc{
int add(int a,int b){ return a+b; }
double add(double a,double b){ return a+b; }
public static void main(String[] args){
Calc c=new Calc();
[Link]([Link](2,3));
[Link]([Link](2.5,3.5));
}
}
Output:
PROGRAM 8
Objective:
Use this keyword to differentiate variables.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Demo{
int x;
Demo(int x){ this.x=x; }
void show(){ [Link](x); }
public static void main(String[] args){
Demo d=new Demo(10);
[Link]();
}
}
Output:
PROGRAM 9
Objective:
Demonstrate abstract class implementation.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
abstract class Vehicle{
abstract void start();
}
class Bike extends Vehicle{
void start(){ [Link]("Bike Start"); }
public static void main(String[] args){
Vehicle v=new Bike();
[Link]();
}
}
Output:
PROGRAM 10
Objective:
Show use of final keyword.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class A{
final void show(){ [Link]("Final"); }
}
class B extends A{
public static void main(String[] args){
B b=new B();
[Link]();
}
}
Output:
PROGRAM 11
Objective:
Create and use a package.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
package mypack;
public class Hello{
public void msg(){
[Link]("Hello Package");
}
}
Output:
PROGRAM 12
Objective:
Implement multiple inheritance using interfaces.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
interface A{ void showA(); }
interface B{ void showB(); }
class C implements A,B{
public void showA(){ [Link]("A"); }
public void showB(){ [Link]("B"); }
public static void main(String[] args){
C obj=new C();
[Link]();
[Link]();
}
}
Output:
PROGRAM 13
Objective:
Handle exceptions using try-catch.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class Ex{
public static void main(String[] args){
try{
int a=10/0;
}catch(Exception e){
[Link]("Error");
}
}
}
Output:
PROGRAM 14
Objective:
Create user-defined exception.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class MyEx extends Exception{
MyEx(String msg){ super(msg); }
}
class Test{
public static void main(String[] args){
try{
throw new MyEx("Custom Error");
}catch(Exception e){
[Link](e);
}
}
}
Output:
PROGRAM 15
Objective:
Demonstrate multithreading and file handling.
Theory:
This program demonstrates core Java concepts relevant to object oriented programming.
It helps in understanding structure, behavior, and real-world implementation of
programming constructs in Java. The program builds conceptual clarity and strengthens
practical coding ability, which is essential for academic and industry-level understanding.
Code:
class T extends Thread{
public void run(){
[Link]("Thread");
}
public static void main(String[] args){
T t=new T();
[Link]();
}
}
Output: