Write a program to show the constructor overloading at the version of constructor in available in a class.

class OverLoad
  {
    int age, num1,num2,num3,sum,e,b,c;
    String name;
    OverLoad(String n,int a)
    {
      name=n;
      age=a;
    }
    void disp()
     {
      System.out.println("Name of the person  :"+name);
      System.out.println("age  of the person  :"+age);
     }
   
    OverLoad(int e,int b,int c)
    {
     num1=e;
     num2=b;
     num3=c;
    
    }
   
     void show()
     {
       int sum=num1+num2+num3;
       System.out.println("sum  =:"+sum);
     }
  public static void main(String args[])
    {
       OverLoad ob=new OverLoad("kapil" ,19);

      
       ob.disp();
       OverLoad ab=new OverLoad(4,5,6);
       ab.show();
    }
 }
     

     

Create a class SimpleCalculator that has functionality of addition, substraction division, multiplication, square and squareroot.

class Calculator
  {
   public void calc()
    {
    int add, sub, mul, a, b, n,sqr,m;
    double div;
    a=Integer.parseInt(System.console().readLine("enter the first no.  :"));
    b=Integer.parseInt(System.console().readLine("enter the second no. :"));
    add=a+b;
    System.out.println("addition of two no.      ="+add);
    sub=a-b;
    System.out.println("substraction of two no.  ="+sub);
    mul=a*b;
    System.out.println("multiplecation of two no.="+mul);
    div=(double)a/b;
    System.out.println("division of two no.      ="+div);
    n=Integer.parseInt(System.console().readLine("enter the no. jiska square niklna hai  :"));
    sqr=n*n;
    System.out.println("square of the no="+sqr);
    m=Integer.parseInt(System.console().readLine("enter the no. jiska square niklna hai  :"));
    double sqtroot=Math.sqrt(m);
    System.out.println("squareroot of the no="+sqtroot);
   }
 
public static void main(String args[])
    {
      Calculator s=new Calculator();
      s.calc();
    
      
    }
 }


 

Create a java program that has three version of add method which can add two, three, and four integers

class VersionAddition
    {
      void firstVersion()
        {
          System.out.println("Enter the two no.s->");
          int a=Integer.parseInt(System.console().readLine("enter the valye fo first no. ="));
          int b=Integer.parseInt(System.console().readLine("enter the valye fo second no.="));
          int sum=a+b;
          System.out.println("sum of two integer ="+sum);
        }
       void secondVersion()
        {
          System.out.println(" ");
          System.out.println("Enter the three no.s->");
          int c=Integer.parseInt(System.console().readLine("enter the valye fo first no. ="));
          int d=Integer.parseInt(System.console().readLine("enter the valye fo second no.="));
          int e=Integer.parseInt(System.console().readLine("enter the valye fo third  no.="));
          int sum=c+d+e;
          System.out.println("sum of three integer ="+sum);
        }
       void thirdVersion()
        {
          System.out.println(" ");
          System.out.println("Enter the four no.s->");
          int f=Integer.parseInt(System.console().readLine("enter the valye fo first no. ="));
          int g=Integer.parseInt(System.console().readLine("enter the valye fo second no.="));
          int h=Integer.parseInt(System.console().readLine("enter the valye fo third  no.="));
          int i=Integer.parseInt(System.console().readLine("enter the valye fo forth  no.="));
          int sum=f+g+h+i;
          System.out.println("sum of four integer ="+sum);
        }
   public static void main(String args[])
      {
        VersionAddition v=new VersionAddition();
        v.firstVersion();
        v.secondVersion();
        v.thirdVersion();
      }
  }

create a package packCal in which main class Calculater and you create 4 different class,add,Multi, sub,Div in packAdd,packMulti,packSub,packDiv.These classes can be accessed through Calculator

This program is completed in 5 steps. These steps are :-


STEP 1 :- 

      ------Make Add package and run it------
package packadd;
public class add
{
public void add1(int a,int b)
{
int c=a+b;
System.out.println("the sum is="+c);
}
}

STEP 2 :- 

      ------Make Subtraction package and run it------
package packsub;
public class sub
{
public void sub1(int a,int b)
{
int c=a-b;
System.out.println("the subtraction is="+c);
}
}

STEP 3 :- 

      ------Make Multiplication package and run it------
package packmul;
public class mul
{
public void mul1(int a,int b)
{
int c=a*b;
System.out.println("the multiplication is="+c);
}
}

STEP 4 :- 

      ------Make Division package and run it------
package packdiv;
public class div
{
public void div1(int a,int b)
{
int c=a/b;
System.out.println("the division is="+c);
}
}

STEP 5 :- 

      ------Finally make a  package Calculator and import all  packages and store all packages in same directory and run it------
package packcal;
import packadd.add;
import packsub.sub;
import packmul.mul;
import packdiv.div;
public class calculator
{
public static void main(String...ghj)
{
add a= new add();
a.add1(5,4);
sub b= new sub();
b.sub1(5,4);
mul m=new mul();
m.mul1(4,5);
div d= new div();
d.div1(5,4);
}
}

Write a program to show the Multi level inheritance.

class A
 {
   void disp()
    { 
      System.out.println("Hello m Dikaoo kya");
    }
 }
class B extends A
 {
    void moll()
    {
      System.out.println("nye nye item chiye kya");
    }
  }
class MultiInheri extends B
  {
    void china()
    {
      System.out.println("sara ka sara mall kharab hai");
    }
  public static void main(String args[])
    {
     MultiInheri ab=new MultiInheri();
     ab.disp();
     ab.moll();
     ab.china();
    }
  }