Showing posts with label JAVA PROGRAMS-Hierarchical Inheritance in Java. Show all posts
Showing posts with label JAVA PROGRAMS-Hierarchical 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-Hierarchical Inheritance in Java

Hierarchical Inheritance in Java

Program Name:- hiear.java

import java.io.*;
class vehicle
{
String regno;
int model;
 vehicle(String r,int m)
 {
 regno=r;
 model=m;
 }
 void display2()
 {
 System.out.print("\nRegistration number\t:"+regno);
 System.out.print("\nModel\t\t\t:"+model);
 }
}
class roadvehicle extends vehicle
{
int noof;
 roadvehicle(String r,int m,int n)
 {
 super(r,m);
 noof=n;
 }
 void display()
 {
 System.out.print("\n\n\t Road Vehicle\n\n");
 super.display2();
 System.out.print("\nNumber of wheel\t:"+noof);
 }
}
class watervehicle extends vehicle
{
int nn;
 watervehicle(String s,int m,int n)
 {
 super(s,m);
 nn=n;
 }
 void display1()
 {
 System.out.print("\n\n\t Water Vehicle\n\n");
 super.display2();
 System.out.print("\nNumber of leaf\t:"+nn);
 }
}
public class hiear
{
 public static void main(String[]args)
 {
 roadvehicle r;
 watervehicle w;
 r=new roadvehicle("TN 58 s 5482",2011,2);
 w=new watervehicle("TN  57 A 5828",2011,10);
 r.display();
 w.display1();
 }
}