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

Java Lab3

Uploaded by

harsha14203
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)
10 views9 pages

Java Lab3

Uploaded by

harsha14203
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

EXERCISE:-1(class and objects)

class Volume

int width,height,depth,v;

Volume(int w,int h,int d)

width=w;

height=h;

depth=d;

void volume()

v=width*height*depth;

void display()

[Link]("the width of box is:"+width+"\n"+"the height of box is:"+height+"\n"+"the


depth of box is:"+depth+"\n"+"the volume of box is:"+v);

class VolumeDemo

public static void main(String[] args)

Volume ob=new Volume(12,14,16);

[Link]();

[Link]();

}
}

EXERCISE:-2.1 POLYMORPHISM

class Sharp

void area(int x,int y)

[Link]("the area of rectangle is:"+x*y+" sq units");

void area(float x)

double z=3.14*x*x;

[Link]("the area of circle is:"+z+" sq units");

void area(double b,double h)

double a;
a=0.5*b*h;

[Link]("the area of triangle is:"+a+" sq units");

class Area

public static void main(String[] args)

Sharp ob=new Sharp();

[Link](10,10);

[Link](5.55f);

[Link](2.5,4.2);

EXERCISE:-2.2 POLYMORPHISM PROGRAM 2


class MyMath

void add(int x,int y)

[Link]("addition of two numbers is:"+(x+y));

void add(float x,float y)

[Link]("addition of two numbers is:"+(x+y));

void add(double x,double y)

[Link]("addition of two numbers is:"+(x+y));

void mul(int x,int y)

[Link]("multiplication of two numbers is:"+x*y);

void mul(float x,float y)

[Link]("multiplication of two numbers is:"+x*y);

void mul(double x,double y)

[Link]("multiplication of two numbers is:"+x*y);

void pow(int x,int y)

[Link]("power of two numbers is:"+[Link](x,y));

void pow(float x,float y)


{

[Link]("power of two numbers is:"+[Link](x,y));

void pow(double x,double y)

[Link]("power of two numbers is:"+[Link](x,y));

class Overheat

public static void main(String[] args)

MyMath ob=new MyMath();

[Link](9,9);

[Link](38.2,38.2);

[Link](321.12,321.12);

[Link](4,4);

[Link](7.7,7.7);[Link](7.482,7.482);

[Link](3,6);[Link](3.3,6.6);[Link](3.32,6.654);

}
POINT CLASS:-

import [Link].*;

class point

double x,y;

point()

x=0;

y=0;

point(double q1,double p1)

x=q1;

y=p1;
}

point(point p1)

x=p1.x;

y=p1.y;

point find_distance(double a,double b)

double dx=a-x;

double dy=b-y;

return new point(dx,dy);

point find_distance(point p)

double dx=p.x-x;

double dy=p.y-y;

return new point(dx,dy);

void display()

[Link]("the points are");

[Link]("("+x+","+y+")");

}
public static void main(String args[])

point p1=new point (12.4,34.5);

point p2=new point(21.4,65.96);

point p3=new point();

p3=p2;

point k,l=new point();

k=p1.find_distance(523.45,897.52);

l=p1.find_distance(p3);

[Link]();

[Link]();

You might also like