To find the area of a Triangle Using User-Defined Method
import java.util.Scanner;
class Xyz
    public static void main(String args[])
             Scanner s= new Scanner(System.in);
                System.out.println("Enter the width of the Triangle:");
          double b= s.nextDouble();
           System.out.println("Enter the height of the Triangle:");
           double h= s.nextDouble();
            double area=AOT(b,h);
         System.out.println("Area of Triangle is: " + area);
    static double AOT(double b,double 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
    public static void main(String args[])
             Scanner s1= new Scanner(System.in);
              System.out.println("Enter the 1st side:");
     int a= s1.nextInt();
       System.out.println("Enter the 2nd side:");
       int b= s1.nextInt();
       System.out.println("Enter the 3rd side:");
     int c= s1.nextInt();
    if((a+b)>c && (a+c)>b && (b+c)>a)
           int s=(a+b+c)/2;
           double area=Math.sqrt(s*(s-a)*(s-b)*(s-c));
           System.out.println("Area of Triangle is: " + area);
     else
       System.out.println("Area of Triangle not exit");
 } }
                                                  Enter the 1st side:
                                                  10
                                                  Enter the 2nd side:
                                                  10
                                                  Enter the 3rd side:
                                                  10
                                                  Area of Triangle is:43.30
To print the details of an employee using constructor
public class Employee {
 String name;
 int age;
 String designation;
 double salary;
 // This is the constructor of the class Employee
 public Employee(String name) {
    this.name = name;
 }
 // Assign the age of the Employee to the variable age.
 public void empAge(int empAge) {
   age = empAge;
 }
 /* Assign the designation to the variable designation.*/
 public void empDesignation(String empDesig) {
   designation = empDesig;
 }
 /* Assign the salary to the variable salary.*/
 public void empSalary(double empSalary) {
        salary = empSalary;
    }
    /* Print the Employee details */
    public void printEmployee() {
      System.out.println("Name:"+ name );
      System.out.println("Age:" + age );
      System.out.println("Designation:" + designation );
      System.out.println("Salary:" + salary);
    }
}
public class EmployeeTest {
    public static void main(String args[]) {
      /* Create two objects using constructor */
      Employee empOne = new Employee("James Smith");
      Employee empTwo = new Employee("Mary Anne");
        // Invoking methods for each object created
        empOne.empAge(26);
        empOne.empDesignation("Senior Software Engineer");
        empOne.empSalary(1000);
        empOne.printEmployee();
        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: