Showing posts with label Multi Level Inheritance in Java. Show all posts
Showing posts with label Multi Level Inheritance in Java. Show all posts

Sunday, 30 March 2014

JAVA PROGRAMS-Java Program using Super key

Java Program using Super key


Program Name:-  superkey.java


class rectangle

{

int length,breadth;

 rectangle(int l,int m)

 {

 length=l;

 breadth=m;

 }

 int area()

 {

 int a;

 a=length*breadth;

 return(a);

 }

}

class box extends rectangle

{

int height;

 box(int l,int b,int h)

 {

 super(l,b);

 height=h;

 }

 int volume()

 {

 int v;

 v=length*breadth*height;

 return(v);

 }

}

class superkey

{

 public static void main(String args[])

 {

 box in=new box(10,10,10);

 int a,v;

 a=in.area();

 v=in.volume();

 System.out.print("\nArea\t:"+a);

 System.out.print(" \nVolume\t:"+v);

 }

}


JAVA PROGRAMS-Interface Demo program in java

Interface Demo program in java

Program Name:- inter1

import java.io.*;

interface demo

{

final double pi=3.14;

abstract double area(int r);

}

interface demo1

{

abstract double circum(int r);

}

class cir implements demo,demo1

{

public double area(int r)

{

return pi*r*r;

}

public double circum(int a)

{

return 2*pi*a*a;

}

}

class inter1

{

public static void main(String arg[])

{

cir c=new cir();

System.out.print("\nCircle\t:"+c.area(5));

System.out.print("\nCircum\t:"+c.circum(5));

}

}


JAVA PROGRAMS-Multi Level Inheritance in Java

Multi Level Inheritance in Java

Program Name:- multi.java

import java.io.*;

class box1

{

int length,width,height;

box1()

 {

 length=0;

 width=0;

 height=0;

 }

box1(int l)

 {

 length=width=height=l;

 }

box1(int l,int w,int h)

 {

 length=l;

 width=w;

 height=h;

 }

int volume()

 {

 int v;

 v=length*width*height;

 return(v);

 }

}

class boxweight extends box1

{

double weight;

boxweight()

 {

 super();

 weight=0;

 }

boxweight(int l,double m)

 {

 super(l);

 weight=m;

 }

boxweight(int l,int w,int h,double m)

 {

 super(l,w,h);

 weight=m;

 }

}

class shipping extends boxweight

{

double cost;

shipping()

 {

 super();

 cost=0;

 }

shipping(int l,double m,double c)

 {

 super(l,m);

 cost=c;

 }

shipping(int l,int h,int w,double m,double c)

 {

 super(l,w,h,m);

 cost=c;

 }

}

class multi

{

public static void main(String args[])

{

shipping s1=new shipping(10,5,7,100.1,150.2);

shipping s2=new shipping(5,2,10,20.0,115.50);

double vol1,vol2;

vol1=s1.volume();

vol2=s2.volume();

System.out.println("\n\t Shipping list");

System.out.print("\n\n Volume weight cost");

System.out.print("\n"+vol1+" "+s1.weight+"rs\t"+s1.cost);

System.out.print("\n"+vol2+" "+s2.weight+"rs\t"+s2.cost);

 }

}