0% found this document useful (0 votes)
14 views9 pages

Oop Print 1 To 6

The document describes 6 programming practical exercises: 1) A Hello World program in Java 2) A program to print a dollar sign pyramid using for loops 3) A program demonstrating classes, methods, and object creation 4) A program studying and implementing method overloading 5) Programs demonstrating single inheritance and multi-level inheritance 6) A program studying and implementing method overriding For each practical, the code and output are described.

Uploaded by

kk Shadab Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views9 pages

Oop Print 1 To 6

The document describes 6 programming practical exercises: 1) A Hello World program in Java 2) A program to print a dollar sign pyramid using for loops 3) A program demonstrating classes, methods, and object creation 4) A program studying and implementing method overloading 5) Programs demonstrating single inheritance and multi-level inheritance 6) A program studying and implementing method overriding For each practical, the code and output are described.

Uploaded by

kk Shadab Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Practical No 1:

Introduction to OOP and installation of JDK, Write a java application to display the message “Hello
World”.

Code :

import java.io.*;

class Example

public static void main(String[] args)

System.out.println("Hello World..."!);

Output :
Practical No 2 :

Develop a program to generate the pyramid of dollar as given below by using for loop.

Code :

import java.io.*;

class pyramid{

public static void main(String[] args){

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

System.out.print(" ");

for(int k=0;k<=i;k++){

System.out.print("$");

System.out.println();

Output :
Practical No 3:

Develop a program to demonstrate the concept of class, method and objects.

Code :

import java.io.*;

class Rectangle{

int l,b;

Rectangle(){

l=10;

b=20;

Rectangle(int x, int y){

l=x;

b=y;

int area(){

return(l*b);

class Area{

public static void main(String args[]){

Rectangle Rect1=new Rectangle();

Rectangle Rect2=new Rectangle(5,10);

int A1=Rect1. area();

int A2=Rect2 .area();

System.out.println("Area using first const:"+A1);

System.out.println("Area using second const:"+A2);

Output :
Practical No 4 :

Develop a program study and implement the concept of method overloading.

Code :

import java.io.*;

class OverloadDemo{

void max(float a,float b){

System.out.println("Method with float arguments");

if(a>b) {

System.out.println("a is greater"); }

Else {

System.out.println("b is greater");

}}

void max(int a,int b) {

System.out.println("Method with int argument");

if(a<b){

System.out.println("a is greater");

}else{

System.out.println("b is greater");

} }

void max(double a,double b){

System.out.println("Method with double argument");

if(a>b){

System.out.println("a is greater");

}else{

System.out.println("b is greater")}}public static void main(String args[]){

OverloadDemo obj=new OverloadDemo();

obj.max(11.2f,5.2f);

obj.max(10,20);

obj.max(11.2,15.2);

}}}
Output :
Practical No 5 :

Develop a program to study and implement inheritance

a) Single inheritance b) Multi-level inheritance

Code : Single Level Inheritance

import java.io.*;

class A {

int i,j;

void showIJ(){

System.out.println("i+"+i+"j+"+j);

}}

class B extends A{

int k;

void showK(){

System.out.println("k="+k);

void sum(){

int z=i+j+k;

System.out.println("sum is"+z);

} } class Inheritance

{ public static void main(String [] args)

{ B b=new B();

b.i=10;

b.j=20;

b.k=30;

b.showIJ();

b.showK();

b.sum();

}}
Output : Single Level Inheritance

Code : Multilevel Inheritance

import java.io.*;

class A{

int n;

A(int a){

n=a;

void show(){

System.out.println("In super class A n is"+n);

}class B extends A{

B(int n)

{super(n);

void show(){

super.show();

System.out.println("B is sub class of A");

class C extends B{

C(int a){

super(a);

void show(){

super.show();

System.out.println("C is sub class of B");


}

class D extends C{

D(int n){

super(n);

void show(){

super.show();

System.out.println("D is sub class of C");

class Multilevel{

public static void main(String args[])

D obj=new D(20);

obj.show();

}}

Output : Multilevel Inheritance


Practical No 6 :

Develop a program study and implement the concept of method overriding.

Code :

import java.io.*;

class Vehicle{

void run(){

System.out.println("Vehicle is running");

class Bike extends Vehicle{

void run(){

System.out.println("Bike is running safely ");

public static void main(String args[]){

Bike obj=new Bike();

obj.run();

Output :

vc

You might also like