Oop Print 1 To 6
Oop Print 1 To 6
Introduction to OOP and installation of JDK, Write a java application to display the message “Hello
World”.
Code :
import java.io.*;
class Example
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{
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:
Code :
import java.io.*;
class Rectangle{
int l,b;
Rectangle(){
l=10;
b=20;
l=x;
b=y;
int area(){
return(l*b);
class Area{
Output :
Practical No 4 :
Code :
import java.io.*;
class OverloadDemo{
if(a>b) {
System.out.println("a is greater"); }
Else {
System.out.println("b is greater");
}}
if(a<b){
System.out.println("a is greater");
}else{
System.out.println("b is greater");
} }
if(a>b){
System.out.println("a is greater");
}else{
obj.max(11.2f,5.2f);
obj.max(10,20);
obj.max(11.2,15.2);
}}}
Output :
Practical No 5 :
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
{ B b=new B();
b.i=10;
b.j=20;
b.k=30;
b.showIJ();
b.showK();
b.sum();
}}
Output : Single Level Inheritance
import java.io.*;
class A{
int n;
A(int a){
n=a;
void show(){
}class B extends A{
B(int n)
{super(n);
void show(){
super.show();
class C extends B{
C(int a){
super(a);
void show(){
super.show();
class D extends C{
D(int n){
super(n);
void show(){
super.show();
class Multilevel{
D obj=new D(20);
obj.show();
}}
Code :
import java.io.*;
class Vehicle{
void run(){
System.out.println("Vehicle is running");
void run(){
obj.run();
Output :
vc