Constructor Programs
Constructor Programs
import java.util.Scanner;
class Xyz
double b= s.nextDouble();
double h= s.nextDouble();
double area=AOT(b,h);
return ((b*h)/2);
Output:
Enter the width of the Triangle:
5
Enter the height of the Triangle:
3
Area of Triangle is: 7.5
---------------------------------------------------------------------------------------------
To Find the Area of a Triangle Using when three sides are given
import java.util.Scanner;
class AreaOfTriangle3
int a= s1.nextInt();
int b= s1.nextInt();
int c= s1.nextInt();
int s=(a+b+c)/2;
double area=Math.sqrt(s*(s-a)*(s-b)*(s-c));
else
} }
String name;
int age;
String designation;
double salary;
empTwo.empAge(21);
empTwo.empDesignation("Software Engineer");
empTwo.empSalary(500);
empTwo.printEmployee();
}
}
Java Program to find the volume of cube, rextangular prism , cone using
polymorphism
class Main{
int volume(int side)
{
return side * side * side;
}
int volume(int length, int breadth, int height)
{
return length*breadth*height;
}
double volume(int radius, int height)
{ return 3.14 * (radius * radius)* height / 3;
}
public static void main(String[] args)
{
Main oe = new Main();
System.out.println("Volume of Cube " +oe.volume(10));
System.out.println("Volume of Rectangular prism " +oe.volume(10,12,30));
System.out.println("Volume of Cone "+oe.volume(5,10));
} }
Output: