20tuee030 Oops Lab Manual 1
20tuee030 Oops Lab Manual 1
OBJECT ORIENTED
PROGRAMMING LAB
ROLL NO:20TUEE030
NAME:KATHIRVEL.K
DEPARTMENT:EEE-A
EX:NO:1a Implementation of Simple Java Program
Comments, Data Types
Objective:
Algorithm:
Step1: Start
Step5: Stop
Program:
OUTPUT:
Result:
The given output is verified.
EX.NO:1b Implementation of simple Java Program
Operators and Expression Evaluation
Objective:
To write simple java program using operators and
expression evaluation.
Algorithm:
Step1: Start
Step2: Input a=10,b=5,c=3,d=1,e=4,f=2
Step3: Display the a+b
Step4: Display a*a/b+c-d*e/f
Step5: Stop
Program:
Output:
Result:
The given output is verified.
EX.NO:1c Implementation of simple Java Program
Conditional Statements and looping
Objective:
To write simple java program using conditional statements
and looping.
Algorithm:
Step1: Start
Step2: Input number=9
Step3: Condition(number<=10)
Step4: If the condition is true display if block
Step5: Inside If block use for loop
Step6: In for loop Display i until condition falce
Step7: If the condition is false display else block
Step8: Stop
Program:
for(int i=1;i<=10;i++)
{
System.out.println(i);
}
}
else
{
System.out.println("The given value is greater than 10");
}
}
}
Output:
Result:
The given output is Verified.
EX.NO:2 Implementation of classes,Objects and
Method in Java
Objective:
To write java program using class,object and method.
Algorithm:
Step1: Start
Step2: Define a class Pubg
Step3: Create main function inside Pubg class
Step4: To create Methods inside main function
Step5: Create object and call methods
Step6: Execute and Display output
Step7: stop
Program:
Output:
Result:
The given output is Verified.
EX.NO:3a Implementation of constructors in java
Default Constructor
Objective:
To write java program using default constructor.
Algorithm:
Step1: Start
Step2: Define a class Devil
Step3: Inside Devil class to create a default constructor
Step4: Create main function inside Devil class
Step5: Create object and call Default constructor
Step6: Execute and Display output
Step7: Stop
Program:
Output:
Result:
The given output is verified.
EX.NO:3b Implementation of constructors in java
Parameterized Constructor
Objective:
To write java program using constructor.
Algorithm:
Step1: Start
Step2: Define a class Pubg
Step3: Inside class to create a parameterized constructor
Step4: Create method to display the values
Step5: Create main function inside Pubg class
Step6: Inside main function to create objects and passing
values
Step7: Inside main function call method
Step8: Execute and Display output
Step9: Stop
Program:
Result:
The given output is verified.
EX.NO:3c Implementation of constructors in java
Copy Constructor
Objective:
To right java program using copy constructor.
Algorithm:
Step1: Start
Step2: Create class Pubg
Step3: Inside class to create a constructor with arguments
Step4: Create copy constructor using object for input
Step5: Create method to display the values
Step6: Inside main function to create objects and passing
values
Step7: Using copy constructor copy the Player1 value to
Player2 inside the main function
Step8: Inside main function call methods
Step9: Execute and Display output
Step10: Stop
Program:
Pubg(Pubg p)
{
Id=p.Id;
Name=p.Name;
}
void display()
{
System.out.println(Id+" "+Name);
Output:
Result:
The given output is verified.
EX.NO:4 Arrays in Java
Objective:
To write java program using arrays.
Algorithm:
Step1: Start
Step2: Define a class Devil
Step3: Create main function inside a Devil class
Step4: Inside main function declare array and initialize
Step5: Inside main function Create for loop using traversing
array
Step6: Execute and Display a[i] until condition falce
Step7: Stop
Program:
Output:
Result:
The given output is verified.
EX.NO:5 Access specifier and packages
Objective:
To write java program using access specifier and packages.
Algorithm:
Step1: Start
Step2: Define a package pack
Step3: Create class A in public
Step4: Create method in Protected
Step5: It’s Save by A.java
Step6: Define another package mypack
Step7: Create another class B which inherit from A
class using the keyword ‘extends’
Step8: Create main function and create object and call
methods
Step9: Execute and display the output
Step10: Stop
Program:
//save by A.java
package pack;
public class A
{
protected void msg()
{
System.out.println("Hello");
}
}
//save by B.java
package mypack;
import pack.*;
class B extends A
{
public static void main(String args[])
{
B obj = new B();
obj.msg();
}
}
Output:
Result:
The given output is verified.
EX.NO:6 Inheritance in java
Objective:
To write java program using Inheritance.
Algorithm:
Step1: Start
Step2: Define a class Single for single inheritance
Step3: Create method inside the Single class
Step4: Create another class Boys which inherit from single
class using the keyword ‘extends’.
Step5: Create method inside boys class
Step6: Define another class one for multilevel inheritance
Step7: Create method inside the one class
Step8: Create another class two which inherit from one
class using the keyword ‘extends’.
Step9: Create method inside two class
Step10: Create another class three which inherit from two
class using the keyword ‘extends’.
Step11: Create method inside three class
Step12: Define another class A for hierarchical inheritance
Step13: Create method inside the A class
Step14: Create another class B which inherit from A
class using the keyword ‘extends’.
Step15: Create method inside A class
Step16: Create another class C which inherit from A
class using the keyword ‘extends’.
Step17: Create method inside C class
Step18: Create another class D which inherit from A
class using the keyword ‘extends’.
Step19: Create method inside D class
Step20: Create Derived class in the name Class Main
Step21: create main function inside main class
Step22: Create object for single inheritance and and call
methods
Step23: Create object for multilevel inheritance and and call
methods
Step24: Create object for single inheritance and and call
methods
Step25: Create object for Hierarchical inheritance and and
Call methods
Step26: Execute and display the output
Step27: Stop
Program:
import java.io.*;
import java.lang.*;
import java.util.*;
//Single Inheritance
class Single {
public void one()
{
System.out.println("Op");
}
}
//Multilevel Inheritance
class one {
public void Mr()
{
System.out.println("Mr");
}
}
class two extends one {
public void Devil() { System.out.println("Devil"); }
}
//Hierarchical Inheritance
class A {
public void print_A() { System.out.println("Name"); }
}
class B extends A {
public void print_B() { System.out.println("Mr Devil"); }
}
class C extends A {
public void print_C() { System.out.println("Op Devil"); }
}
class D extends A {
public void print_D() { System.out.println("Devil Op"); }
}
// Drived class
public class Main {
public static void main(String[] args)
{
//Derived Class for Single inheritance
System.out.println("Single Inheritance is start");
Boys w = new Boys();
w.one();
w.two();
System.out.println("Single Inheritance is End");
Output:
Result:
The given output is verified.
EX.NO:7 Abstract Classes and Interfaces
Objective:
To write java program using Abstract classes and interfaces.
Algorithm:
Step1: Start
Step2: Define a package Pubg
Step3: Create interface player
Step4: Create method
Step5: Create class Information which implements from
player
Step6: Create method
Step7: Create another class Pubg
Step8: Inside pubg class create main function
Step9: Inside main function Create object and call methods
Step10: Execute and display the output
Step11: Stop
Program:
package Pubg;
interface Player
{
String Name="Devil";
void computepoints();
}
class Information implements Player
{
int point;
public void computepoints()
{
point=2*200;
}
void display()
{
System.out.println(Name);
System.out.println(point);
}
}
public class Pubg
{
public static void main (String[] args)
{
Information Mr=new Information();
Mr.computepoints();
Mr.display();
}
}
Output:
Result:
The given output is verified.
EX.NO:8 Strings and String Functions
Objective:
To write java program using strings and string function.
Algorithm:
Step1: Start
Step2: Define a Class Player
Step3: Create main function inside Player class
Step4: Create String by java String literal
Step5: Create char
Step6: Convert char array to string
Step7: Create java string by new keyword
Step8: Using print statement to display the output
Step9: Stop
Program:
Output:
Result:
The given output is verified.
EX.NO:9 Exception Handling
Objective:
To write java program using exception handling.
Algorithm:
Step1: Start
Step2: Create a main class (“NestTry”) and main method in
it.
Step3: Now,create multiple try and catch blocks for nested
try to catch the exceptions.
Step4: Catch block should contain the type of exceptions
which you need to catch (Arithmetic Exception, Array
Index Out Of Bounds Exception).
Step5: Stop.
Program:
if(a==2)
{
int c[]={1};
c[42]=99;
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array Index Out-Of-Bounds: "+e);
}
}
catch(ArithmeticException e)
{
System.out.println("Divide by 0 "+e);
}
}
}
Output:
Result:
The given output is verified.