25) Create a package TYBSc which will have 2 classes as class Mathematics with a methods to add two numbers, add three float numbers and class Maximum with a method to find maximum of three numbers. (Make use of finalize)


Mathematics.java

package tybca;
public class Maths
{
int a,b,add;
double x,y,z,sum;
public Maths(int a,int b)
{
add=a+b;
System.out.println(“addition of 2 integer is :->”+add);
}
public Maths(double x, double y, double z)
{
sum=x+y+z;
System.out.println(“addition of 3 float is :->”+sum);
}
protected void finalize()
{
a=b=0;
x=y=z=0;
}
}
Maximum.java
package pack2;
public class Maximum
{
int a,b,c;
public Maximum(int a,int b,int c)
{
if((a>b) &&(a>c))
System.out.println(a+” is Maximum “);
else
{
if(b>c)
System.out.println(b+” is Maximum “);
else
System.out.println(c+” is Maximum “);
}
}
}
PackDemo.java
import tybca.*;
class PackDemo
{
public static void main(String args[])
{
Maths obj=new Maths(2,6);
Maths obj1=new Maths(1.0,2.0,3.0);
Maximum m =new Maximum(8,9,5);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s