Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

OOP, OOPS Concept in Java:-

Object-oriented programming structure, It is used to create real-world based applications using dynamic memory allocation, security, reusability, and extend-ability features.



Rules for OOP'S:-

1 Class and Object:-

Class:-   It is used to define the characteristics of an object using data member and member function.

we can define multiple objects definitions using a class but all objects should be related to each other.

class Classname
{
      Data member;

      Member Function;

       Constructor;

       Static Block;

       Initializes block;

       Property;

       class Classname{}

       Object
 

}


Object:-  It is a real-world entity that has an identity, state, and behavior.

for example, Electronics is the class which has multiple objects such as Laptop, Mobile, Television
, Camera etc.


How We Create Real-world Java Program?


1  Business Class:- this class contain only object definition


2 Executable Class:- 
 this class contains main() to call any other class object.


Program Explanation Of Student Class:-

Business Class:-

import java.util.Scanner;
class Student
{
   int no;
   String sname;
   Scanner sc = new Scanner(System.in);
   void accept()
   {
      System.out.println("enter rno");
      rno=sc.nextInt();
      System.out.println("enter name");
      sname=sc.next(); 
       

   }
   void display()
   {
       System.out.println("rno is "+rno);
       System.out.println("name is "+sname); 
   }

}


Executable Class:-


class StudentMain
{
    public static void main(String args[])
    {
        Student obj = new Student();
        obj.accept();
        obj.display();
        Student obj1 = new Student();
        obj1.accept();
        obj1.display();     

    }

}

For Multiple Object using Student Object Array 
 
class StuMain
{
    public static void main(String args[])
    {
        int num,r;
        String n;
        System.out.println("enter number of students");
        Scanner sc = new Scanner(System.in);
        num=sc.nextInt();        
        Student obj[]= new Student[num];
        for(int i=0;i<num;i++)
        {
             System.out.println("Enter element for "+i+" index");
             obj[i]=new Student();
             System.out.println("enter rno");
             r=sc.nextInt();
             System.out.println("enter name");
             n=sc.next();
             obj[i].accept(r,n);
            
        }
        System.out.println("Student information is ");
       for(int i=0;i<num;i++)
       {
            obj[i].display();
       }

    }

}


ASSIGNMENT:-

CREATE CLASS TO MANAGE EMPLOYEE INFORMATION USING EMPID, EMP NAME, JOB, SALARY.


MARKSHEET PROGRAM USING FIVE DIFFERENT STUDENT AND FIND MAX 
OBTAINED MARKS,  Aggregate marks.

Solution 

import java.util.Scanner;
class Marks
{

   int mark[];
   float per=0,total;
   String sub[];
   void enterSubjectMarks(String sub[],int mark[])
   {
        this.sub = sub;
        this.mark = mark;
        
 
   }

   void calculateMarks()
   {
     for(int i=0;i<mark.length;i++)
      {
          total = total+mark[i];
      } 
      per = total/mark.length;
      System.out.println("Percentage is "+per);

   }

  

   


}


class MainMark
{

    public static void main(String args[])
    {
       Scanner sc = new Scanner(System.in);
       String sub[] = {"physics","chemistry","maths","english","hindi"};
       System.out.println("Enter number of students");
       Marks obj[] = new Marks[sc.nextInt()];
       float ag=0;
       for(int i=0;i<obj.length;i++)
       {
             obj[i] = new Marks();
             int marks[] = new int[5];
            
             System.out.println("Enter Record for student " + (i+1));
             for(int j=0;j<5;j++)
             {
                     System.out.println("Enter marks for "+sub[j]);
                     marks[j] = sc.nextInt();

             }  
            obj[i].enterSubjectMarks(sub,marks);
            obj[i].calculateMarks(); 
            ag+=obj[i].per;
            

       }   
       System.out.println("Agreegate pecentage is " + ag/obj.length);
    }


}

ATM Program with unlimited users, first admin add users with pin, amount and account than user module loaded ask pin three times and perform all operation.




Component of Class in Java:-

1 Data member or Variable:-

It is called variable and constant of class, it is used to declare attribute of Object 
We can declare two different types of the attribute, class type attribute will be declared by static data members of the class.
The instance attribute will be declared by the dynamic data members of the class.

Static Data Member:-

It will allocate memory at compile-time and declare by static keyword. Static Data Member will be called by Classname.

static datatype variable-name = value

it is used to create a shared variable for multiple users in real-world applications.

all local variables which will be declared under main() or any other static method then it will be static.

if we want to declare a global static variable underclass then we use the static keyword.

static datatype identifier=value;

static int x=100;


class Staticdemo
{
   static int x=10;   //global static
   static int y=20;
   public static void main(String args[])
   {
      int z=22;      //local static
      x=100;
       
      System.out.println(x+y);

   } 



}

class StaticExample
{
    static int x,y,z;
    static void addition()
    {
           x=100;
           y=200;
           z=x+y;
           System.out.println(z);
    }

    public static void main(String args[])
    {
          addition();

   }

}

Static Example With Different Class:-

class Staticdemo
{
   static int x=10;
   static int y=20;
   


}

class StaticMain
{
public static void main(String args[])
   {
      int z=22;
      Staticdemo.x=100;
       
      System.out.println(Staticdemo.x+Staticdemo.y);

   } 

}





Another Example of Static:-

class StaticExample
{
    static int x=100,y=209,z;
    static void addition()
    {
          
           x=100;
           y=200;
           int x=20;
           z=x+y;
           System.out.println(z);
    }

   

}

class StaticMain
{
     public static void main(String args[])
    {
          StaticExample.addition();
           System.out.println(StaticExample.x);

     }


}

2  Instance variable or Dynamic variable or non-static variable:-


This type of variable will allocate memory at run time and it will be called by Object.

If we want to allocate different memory for different user's then we use the instance variables.

class Classname
{
      datatype identifier;
      

}


when we declare any variable under the instance method or underclass then it will be a dynamic variable. static keyword not allowd under instance method.


class A
{
      int x,y;

}


Explanation by program 

class DynamicDemo
{
    int x,y;
    public static void main(String args[])
    {
        DynamicDemo obj = new DynamicDemo();
        obj.x=100;
        obj.y=200;
        System.out.println(obj.x+obj.y);

    }   


}

Another Example:-

class StaticExample
{
     int x=100,y=209,z;
     void addition()
    {
          
           x=100;
           y=200;
           int x=20;
           z=x+y;
           System.out.println(z);
    }

   

}

class StaticMain
{
     public static void main(String args[])
    {
          StaticExample ram = new StaticExample();
         
          ram.addition();
           System.out.println(ram.x);

          StaticExample shyam = new StaticExample();
          
          shyam.addition();
          shyam.x=300;
           System.out.println(shyam.x);

     }


}

2 Member function or Method:-

Member function or method both are the same according to object orientation terminology we will tell member function to the method.


It is used to define data members of a class using the member function. if data member will be static
then we create a static member function and if data members will be dynamic then we will create a dynamic member function.

because we should never access data members directly, it should be defined by member function for security concern.


class A
{
   static int a,b=3,c; //static,class
   int x=10,y=20,z;  //instance,dynamic
   static void additionFunction()
   {
        a=1000;
        b=2000;
        c=a+b;
        System.out.println(c);
   } 
   void subFunction()
    {
        x=100;
        y=200;
        z=x-y;
        System.out.println(z);
        
    }
   public static void main(String ram[])
   {
       A obj= new A();  //new --> dynamic memory allocation 
       obj.additionFunction();
       obj.subFunction();
       
   }

}


type of member function:-



1 static member function


   static returntype methodname()
   {

   }


it will be called by Class name

Complete Explanation of static component of class:-

class StaticDemo
{
    private static int x,y;
    static void addition()
    {
       x=100;
       y=200;
       System.out.println(x+y);

    }  
    

}

class Staticmain
{
   public static void main(String args[])
    {
          StaticDemo.addition();
        

    }   


}

common interview question for the static method:-


when we call static data member or static member function using object then what will be the output?


It will be successful to compile and execute and provide proper output but data not assigned into runtime memory it will be assigned into compile-time memory. it is not the prefered way to call static because unwanted memory will be created.














2 dynamic member function
  
   returntype methodname()
   {

   }

It will be called by the object

Example of dynamic:-
class DynamicDemo
{
    private int x,y;
    void addition()
    {
       x=100;
       y=200;
       System.out.println(x+y);

    }  
    public static void main(String args[])
    {
        DynamicDemo obj = new DynamicDemo();
        obj.addition();
        

    }   


}

Type of Member Function According to Parameters:-

1 Default:-


We can not pass any value from the calling function to the called function. Input will be defined under the function block.


Type of Default Function:-

1.1 With Return Type:-

it will return output data which can be used by any other program.

AccessSpecifier Datatype  Methodname()
{
  
       return  output;

}

public int fun()
{
    return 10;
}


public static int  fun()
{
    return 10;
}


1.2 Without Return Type:-

We can not return any output data from the calling function to called function.

Input and output both will be defined under the function block.


acessspecifier  void functionname()
{


}


public void fun()
{
   int a=100;
   int b=200;
  System.out.println(a+b);

}

public static void fun()
{
    int a=100;
   int b=200;
  System.out.println(a+b);
}



2 Parametrized:-

using this we can pass value from calling function to called function using a parameter.

parameter identifier is called arguments.


With Return Type:-

accessspecifier  returntype methodname(datatype arguments)
{


}

Without Return Type

access specifier  void method name(datatype arguments)
{


}


Complete Explanation of Method:-


class MethodExample
{
    int a,b;
    void fun1()
    {
       a=10;
       b=20;
       System.out.println(a+b);
        
    }

    int fun2()
    {
         a=100;
         b=20;
         return a-b;

    } 
    void fun3(int a,int b)
    {
         System.out.println(a+b);
    } 
   
    int fun4(int a,int b)
    {
         return a+b;
    } 


}

class Methodmain
{
   public static void main(String args[])
   {
        MethodExample obj = new MethodExample();
        obj.fun1();
        int res = obj.fun2();
        System.out.println(res); 
        obj.fun3(100,20);
        int res1 = obj.fun4(100,2);
        System.out.println(res1); 
           

   }


}


Example of Static and Dynamic member function in Single Class:-

class MF
{
   private static int a,b;
   private int x,y;
   
   static void addition()
   {
       MF o = new MF();
       a=100;  
       b=200;
       o.x=100;
       o.y=200;
       System.out.println("static addition"+(a+b));
       System.out.println("dynamic addition"+(o.x+o.y));
      
   } 
    void sub()
   {
    
       MF.a=10;  
       MF.b=20;
       x=100;
       y=200;
       System.out.println("static addition"+(MF.a+MF.b));
       System.out.println("dynamic addition"+(x+y));
      
   } 

  


}
class MFMain
{
     public static void main(String args[])
     {
       MF.addition();
       MF obj2 = new MF();
       obj2.sub();
       
     }

} 




How to pass an array as a parameter and return multiple values in java?

class Ope
{
  int sum; 
  
   void add(int a[])    //param array
   {
        sum=0;
        for(int s:a)
        {
           sum+=s; // sum = sum+s
        } 
        System.out.println(sum);
   } 
   int[] divide()   // multiple value return
   {
        int arr[] = {3,4,5,6,6,7,8,9};   
        return arr;
   } 


}


class OpeMain
{
    public static void main(String ram[])
    {
         Ope obj = new Ope();
         int arr[] = {2,3,4,5,56,67,89};
         obj.add(arr);
         int arr1[] = obj.divide();
         for(int i:arr1)
         {
                 System.out.println(i);
         }
        

    }

}


2) Parametrized Jagged Array Example?

import java.util.Scanner;
class A
{
   void jArr(int arr[][])
   {
         for(int i=0;i<arr.length;i++)
         {
             for(int j=0;j<arr[i].length;j++)
             {
                      System.out.print(arr[i][j] + " ");
             }
            System.out.println();         

         }
   }

}


class Amain
{
    public static void main(String args[])
    {
        int arr[][]=new int[2][];
        arr[0] = new int[5];
        arr[1] = new int[2];
        for(int i=0;i<arr.length;i++)
         {
               for(int j=0;j<arr[i].length;j++)
                 {
                      System.out.println("Enter element for "+i+j+ "index");
                      arr[i][j]=new Scanner(System.in).nextInt();
                 }

         } 
       
        A obj = new A();
        obj.jArr(arr);

    }

}



Assignment:-

1) WAP to perform addition of matrix multiplication using param array with return type?

2) WAP to count total prime elements on the jagged array and show max prime elements using param array with return type




3 Constructor:-

It is used to Initialize dynamic data members of a class, Constructor name, and class name both will be the same.

A constructor has no user define a return type, it will be the return address of class type.

when we compile any class then the constructor block will be created automatically.

Actual class:-
class A
{


}

After compilation
class A
{
     A()
    {


   }

}

Note:-  Default Constructor by default present into class. it will be called when we create an Object.


TYPE   OF CONSTRUCTOR:-

1)  Default or no parameter:-

    The default constructor has also two different type

   1)  Class type default Constructor

   2)  User define default Constructor

    we can not pass any value from an object

2) Parameterized constructor

   we can pass parameter using object

   2.1)  One parameter, Two Parameter,...

  2.2)   Reference param or Object Param,.......

Example of Constructor with the complete program:-

class ConsDemo
{
   int a,b;
   ConsDemo()
   {
      a=100;
      b=200;
   }  
  ConsDemo(int a,int b)
   {
       this.a=a;
       this.b=b;
   }  

   ConsDemo(ConsDemo obj)
   {
       this.a=obj.a;
       this.b=obj.b; 

   } 
   void display()
   {
      System.out.println(a*b);
   }

}
class ConsMain
{
     public static void main(String args[])
     {
          ConsDemo obj = new ConsDemo();
          obj.display();
          ConsDemo obj1 = new ConsDemo(10,20);
          obj1.display();
          ConsDemo obj2 = new ConsDemo(obj1);
          obj2.display(); 

      }


}


Another Example of Constructor:-

class Consdemo
{
     int a;
     Consdemo()
     {
         a=2;
     } 
     Consdemo(int a)
     {
        this.a=a;
     }

    Consdemo(Consdemo obj)
    {
       this.a=obj.a;

    }
    void displaySquare()
    {
        System.out.println("square is "+a*a);
    }

public static void main(String args[])
{
    Consdemo obj = new Consdemo();
    obj.displaySquare();
    Consdemo obj1 = new Consdemo(12);
    obj1.displaySquare();
    Consdemo obj2 = new Consdemo(obj1);  //obj2=obj
    obj2.displaySquare();
    
}

}


Another Example using a static variable:-

 
4 Static Block:-

It is used to initialize static data members of the class. The static block will be called before main() but the constructor will be called after main()  when we create an object.

static block is also called an anonymous block on Java program?



class StaticBlockExample
{
   static int a,b;
   static
   {
      a=100;
      b=200; 
      System.out.println("Static Block");

   }
   static void display()
   {
      System.out.println(a+b);
   }

   public static void main(String args[])
   {
      StaticBlockExample.display();
   
   } 



}


Another Program of Static Block to UnderStand:-

class Stblock
{
    static int a=10;
    static
    {
      a=5;
    }
    public static void main(String args[])
    {
       System.out.println(a);
    }
     static
    {
      a=1;
    }
}
 


5 Init Block:-

This block is used to initialize any data member before the constructor means if the program has a static block, constructor, and init block then the first static then main(), init, and after that constructor will be called.


Complete Program with an explanation of StaticBlock, Init, Constructor, and main()

Init block will never call without object creation because it will always call before the constructor.


class StaticBlockExample
{
   static int a,b;
   int x,y;
   {
       System.out.println("INIT");
      x=10;
      y=20;
   }
   StaticBlockExample()
   {
      System.out.println("CONSTRUCTOR");
      System.out.println(x+y);
   }
    

   static
   {
      a=100;
      b=200; 
      System.out.println("Static Block");

   }
   static void display()
   {
      System.out.println(a+b);
   }

   public static void main(String args[])
   {
      System.out.println("Main");
      //StaticBlockExample obj = new StaticBlockExample();
     // StaticBlockExample.display();
   
   } 



}


Example of Init Block and Constructor:-

class A
{
  int a,b;

  {
     a=100;
     b=200;
     
   }
   
   A()
   {
      System.out.println(a+b);
   }

   public static void main(String args[])
   {
       A obj = new A();
   }

   
  {
     a=10;
     b=20;
    

  }

}


.....................................................................................................................................


Another Program for Static Block, Init Block, Constructor?


class Stblock
{
    static int a=10;
    int b=200;
    Stblock()
    {
      System.out.println("Default Constructor"+b);
    }
    {
         b=5;
    }
    static
    {
      a=5;
    }
    public static void main(String args[])
    {
       System.out.println(a);
       Stblock obj = new Stblock();
      
    }
     static
    {
      a=1;
    }
}



6 Properties

7 Inner class

8 Object





2 Data Abstraction and Data Encapsulation:-

Abstraction means Data hiding, it is used to hide non-essential details and show only essential details in an application.

Abstraction is used to provide security and accessibility options in the project.

In Java programming language we can implement data abstraction using three different ways.

1) Using Access Specifier:-

1.1 private:-  it is used to provide accessibility only in the same class. we can not access private data members into another class in the same package and different packages.

class A
{
   private int a;
   private void fun()
   {

   }

}
note:-  outer class never will be private in java because the class-default scope is the "default" modifier.




1.2 default:- 

 it is used to provide accessibility in the same package all classes.

  int b;
  void fun1()
  {

  }

if we do not write any access modifier then "default" will be considered



3 protected:-  


it can be accessed in other package classes but inheritance is required. without inheritance, it is similar to the default.

protected int a;
protected void fun2()
{

}

4 public:- it can be accessed in other projects and the cross packages also, it has more strength as compared to other access specifiers.

  public int a;
  public void fun3()
  {

  }


2) Using Abstract Class


3) Using Interface


Data Encapsulation:- Binding of data in a single unit, encapsulation is used to protect the direct accessibility of data members, it provides accessibility of data members using member function.



class A
{
    public int a=10,b=20;  //not encapsulated
     int a=100,b=200;    // wrong 
   
}
class A
{
    private int a,b;  //encapsulation
    void fun()  //fun() encapsulate a and b
    {
     a=10;
     b=20;
    }


}


note:-  these rules of oops is used to provide security and accessibility option in the program.


Live example of ATM Operation using data abstraction and data encapsulation:-

import java.util.Scanner;
class Bank
{
   int bal=5000;
   Scanner sc  = new Scanner(System.in);
   private void credit(int amt)
   {
      bal+=amt;  
 
   }

   private void debit(int amt)
   {
      bal-=amt;
   }

   private void checkbalance()
   {
       System.out.println("balance is "+bal);
   }
   
   private int accept()
     {
         System.out.println("Enter amount");
         int amt = sc.nextInt();
         return amt;
     }

   void login(int pin)
   {
       if(pin==1234)
        {
            while(true)
            {
          System.out.println("press c for credit \n press d 

for debit \n press b for balance \n press e for balance");
            char ch = sc.next().charAt(0);
            switch(ch)
            {
            case 'c':
            credit(accept());
            break;
            case 'd':
            debit(accept());
            break;
            case 'b': 
            checkbalance();
            break;
            case 'e': 
            System.exit(0);
            break;
            default:
            System.out.println("wrong choice");
            break; 
            }
            }

        }

   }
   

}


class Customer
{
   public static void main(String args[])
   {
         Bank obj = new Bank();
      // obj.credit(1200);
         System.out.println("Enter pin code");
         int pin = obj.sc.nextInt();
         obj.login(pin);
   }

}

Polymorphism:-


Poly means many and "morphism" means forms using this we can increase the usability of function and operator in the program.

Polymorphism is used to provide overloading and overriding features.

Java does not support operator overloading because we can not re-define the operator definition.


We can reduce the extra memory space of the program using polymorphism.


Type of Polymorphism:-

1 Static Polymorphism:-  it will perform the operation at compile time hence it is also early binding.

1.1 function overloading:-

We will create the same name function only the parameters will be different, constructor is the best example of function overloading,

println() is the best example of function overloading.

package p1;

public class Operation {
  void add(int a,int b)
  {
      System.out.print(a+b);
  }
  void add(int a,float b)
  {
      System.out.print(a+b);
  }
  void add(float a,int b)
  {
      System.out.print(a+b);
  }
  void add(float a,float b)
  {
      System.out.print(a+b);
  }
  public static void main(String args[])
  {
      Operation obj = new Operation();
   //   obj.add(100,200);
     obj.add(100.2F,200.2F);
  }
}

2 Dynamic Polymorphism:-  it will perform the operation at runtime using inheritance.

2.1 function overriding


Create the Same name method from base class to derived class only functionality will be different.

note:-  function name  and return type should be the same from base class to derived class 

class A
{
    void fun()
    {

    }

}
class  B extends A
{
  void fun()  //correct
    {

    }
 
  int fun()  //wrong
    {

    }




1 using Abstract class:-  

We have been discussed this topic below.


2 using interface:-   

We have been discussed this topic below. 


3 using normal class


A complete example of Overriding:-

class Exam
{
   public void boardInfo()
   {
         System.out.println("RGPV");   
   }
   public void examPattern()
   {
        System.out.println("Number System");
   }

}
class Examnew extends Exam
{
   public void examPattern(String s)
   {
        System.out.println("Grade System"+s);
   }
   public void examPattern()
   {
         System.out.println("Grade System");
   }

    public static void main(String args[])
     {

        // Exam obj = new Examnew();
        // Exam obj = new Exam();
         Examnew obj = new Examnew();
         obj.boardInfo();
         obj.examPattern();
      }

}






Program Explanation:-
................................................................................................................................

class SI
{
    float p,r,t,si;
    void accept(float p,float r,float t)
    {
        System.out.println("FLOAT,FLOAT,FLOAT"); 
        this.p=p;
        this.r=r;
        this.t=t;
    }
    void accept(int p,int r,int t)
    {
        System.out.println("INT,INT,INT");
        this.p=p;
        this.r=r;
        this.t=t;
    }
    void accept(int p,float r,int t)
    {
        System.out.println("INT,FLOAT,INT");
        this.p=p;
        this.r=r;
        this.t=t;
    }
    void accept(int p,float r,float t)
    {
        System.out.println("INT,FLOAT,FLOAT");
        this.p=p;
        this.r=r;
        this.t=t;
    }
    void accept(float p,int r,int t)
    {
        System.out.println("FLOAT,INT,INT");
        this.p=p;
        this.r=r;
        this.t=t;
    }

    void calcsi()
    {

        si = (p*r*t)/100;
    }
    void add()
    {
       si = (p+r+t);
    } 

    void display()
    {

       System.out.println(si);
    } 

}
class SIMain
{
     public static void main(String args[])
     {
        SI obj = new SI();
        obj.accept(2,35.45F,4);
        obj.calcsi();
        obj.display(); 
       
     }



}


...............................................................................................................................................................


Class and Object Related Program to Calculate Simple Interest?
.......................................................................................................................
class SI
{
    float p,r,t,si;
    void accept(float p,float r,float t)
    {
        this.p=p;
        this.r=r;
        this.t=t;
    }

    void calcsi()
    {

        si = (p*r*t)/100;
    }
    void add()
    {
       si = (p+r+t);
    } 

    void display()
    {

       System.out.println(si);
    } 

}
class SIMain
{
     public static void main(String args[])
     {
        SI obj = new SI();
        obj.accept(12000.2F,2.2F,2.2F);
        obj.calcsi();
        obj.display(); 
        SI obj1 = new SI();
        obj1.accept(12000.2F,2.2F,2.2F);
        obj1.add();
        obj1.display(); 

     }


}

..............................................................................................................................................................

Inheritance:-
.............................................................................................................................................................

It means re-usability, using this concept of oops we can adopt the features of the base(parent) class to derived(child) class and reduces common code from an application.

Type of Inheritance:-


1 Single:-  Base class to derived class

Base   class or Parent class both will be the same


Derived class or Child class both will same.


2 Multilevel:-    Base class to derived class to sub derived


Base


Derived


Sub-Derived



3 Hierarchical:-     

it will provide inheritance using tree structure from base class to subderived1,subderived2

                                                          Base


          Derived1                                                             Derived2






Example of Single Inheritance:-

class Admin
{
    int aid;
    String aname; 
    void accept(int aid, String aname)
    {
       this.aid = aid;
       this.aname=aname;

    }
    void display()
    {
       System.out.println("aid "+aid+" name is "+aname);

    }

}

class Employee extends Admin
{
     int salary;
     void accept1(int salary)
     {
        this.salary=salary;
     }
     void display1()
     {
       System.out.println("Salary is "+salary);
     }

}

class EmpMain
{
    public static void main(String args[])
    {
       System.out.println("Employee Info");
       Employee obj = new Employee();
       obj.accept(1001,"emp");
       obj.accept1(12000);
       obj.display();
       obj.display1();
       System.out.println("Admin Info");
       Admin obj1 = new Admin();
       obj1.accept(1000,"admin");
       obj1.display();
       

    }


}


Practical Explanation of Multilevel Inheritance using Admin---> EMP--->  OtherStaff?




public class Admin {
int aid;
String sname;
void accept(int aid,String sname)
{
    this.aid=aid;
    this.sname=sname;
}
void display()
{
    System.out.print("id is "+aid);
    System.out.print("name is "+aid);
}

}
 


......................................


public class Employee extends Admin {
int salary;
void accept1(int salary)
{
    this.salary=salary;
   
}
void display1()
{
    System.out.print("Salary is "+salary);
   
}

}
.....................................


public class OtherStaff extends Employee{
    int bonus;
    void accept2(int bonus1)
    {
        bonus=bonus1;
    }
    void display2()
    {
        System.out.println("Bonus is "+bonus);
    }
   

}
EmpMain Class for Accessbility:-


package p1;

public class EmpMain {

    public static void main(String[] args) {
       
        System.out.println("Employee Information");
        //Employee obj = new Employee();
        OtherStaff obj= new OtherStaff();
        obj.accept(1001,"manish kumar");
        obj.accept1(12000);
        obj.display();
        obj.display1();
        System.out.println("\nAdmin Information");
        //Admin obj1 = new Admin();
        //Employee obj1 = new Employee();
        OtherStaff obj1= new OtherStaff();
        obj1.accept(1000, "admin");
        obj1.display();
       
        System.out.println("\nOtherStaff Information");
        OtherStaff obj2 = new OtherStaff();
        obj2.accept(1002, "other staff");
        obj2.accept1(6000);
        obj2.accept2(100);
        obj2.display();
        obj2.display1();
        obj2.display2();
       

    }

}
 


Example of Hierarchical Inheritance:-


Admin is the base class and it has two different subclasses, Employee and other staff.


Practical Explanation of Admin Base Class, Employee Derived Class, and Other Staff derived class.




public class Admin {
int aid;
String sname;
void accept(int aid,String sname)
{
    this.aid=aid;
    this.sname=sname;
}
void display()
{
    System.out.print("id is "+aid);
    System.out.print("name is "+aid);
}

}
 


......................................


public class Employee extends Admin {
int salary;
void accept1(int salary)
{
    this.salary=salary;
    
}
void display1()
{
    System.out.print("Salary is "+salary);
    
}

}
.....................................


public class OtherStaff extends Admin{
    int bonus;
    void accept2(int bonus1)
    {
        bonus=bonus1;
    }
    void display2()
    {
        System.out.println("Bonus is "+bonus);
    }
    

}

....................................................................................................................................
Main Class Code in Java:-


public class EmpMain {

    public static void main(String[] args) {
        
        System.out.println("Employee Information");
        Employee obj = new Employee();
      
        obj.accept(1001,"manish kumar");
        obj.accept1(12000);
        obj.display();
        obj.display1();
        System.out.println("\nAdmin Information");
        //Admin obj1 = new Admin();
        //Employee obj1 = new Employee();
        OtherStaff obj1= new OtherStaff();
        obj1.accept(1000, "admin");
        obj1.display();
        
        System.out.println("\nOtherStaff Information");
        OtherStaff obj2 = new OtherStaff();
        obj2.accept(1002, "other staff");
      
        obj2.accept2(100);
        obj2.display();
    
        obj2.display2();
        

    }



ASSIGNMENT  OF INHERITANCE?


Area of Triangle, Rectangle, Circle using possible Inheritance?


Class Addition, Subtraction, Multiplication, Division using possible Inheritance?


Abstract class in Java:-
............................................................................................


It is the special class of JAVA which is used to contain a set of abstract methods to hide actual details.

we can not create an object of an abstract class, it will be extended by Child class.

abstract class use function overriding by default because all abstract methods must be defined.
we will use the abstract keyword to declare an abstract class and abstract method.

abstract method:-   "it is the special method in java which has the only declaration, it does not contain method body"

the abstract method only will be declared under abstract class and interface in java.




Syntax of Abstract Class:-

 abstract class Classname


       static variable;   
      instance variable;
       abstract access-specifier return-type method-name();
       accessspecifier returntype methodname()
      {

      }
     
   main();

}


 We can create the only reference for abstract class, not object.


note:-  abstract class contain main() but we can not create an object of abstract class but another class object can be created.






Advantage of an abstract class:-

1)  Data abstraction:-   abstract class provides class-level data abstraction.


2) Data Contract:-  all methods of an abstract class must be defined by the child class. it is used to provide a high-level design approach for project development.



Simple Example of Abstract class:-

package scsbranch1;

abstract class Ope {
abstract public void add();
abstract public void multi();

}

class Operation extends Ope
{

@Override
public void add() {
// TODO Auto-generated method stub
}

@Override
public void multi() {
// TODO Auto-generated method stub
}
}


Example of Abstract class:-


abstract class Bank
{
     String s;
     public void info()
     {
       s="SBI";
       System.out.println("welcome in "+s);
     }
     abstract void credit(int amt);
     abstract void debit(int amt);
     abstract void checkbalance();     

}


class BankTransaction extends Bank
{

void checkbalance()
{
System.out.println("balance ");
}

void debit(int amt)
{
System.out.println("debit amount is "+amt);
}

void credit(int amt)
{
System.out.println("credit amount is  "+amt);
}

public static void main(String args[])
{
  // Bank obj = new BankTransaction();  //ok

     BankTransaction obj = new BankTransaction();  //ok

//    Bank obj = new Bank();   // not ok
  
   obj.info();
   obj.credit(12000);

}
  
}

Another Example of Abstract class?

for example, if we want to create a device then how many features will be implemented in the Mobile class that will be declared by Abstract class and it must be implemented by Child class.


abstract class MyDevice
{
   void deviceInfo()
    {
      System.out.println("welcome in mobile device ");
    }
   abstract void camera();
   abstract void multimedia();
   abstract void calling();

}


class Mobile extends MyDevice   //concrete class
{
void calling()
{
System.out.println("calling ");
}
void multimedia()
{
System.out.println("multimedia");
}

void camera()
{
System.out.println("camera ");
}
public static void main(String ar[])
{

  MyDevice obj = new Mobile();
  obj.calling();
  obj.multimedia();

}
}

An abstract class is used to implement a design pattern in java project where we use the top layer, middle layer, and user layer, top layer is used to declare a set of methods and the middle layer will implement it that can be possible with abstract class and interface.




.....................................................................................................................................................................
Final Class:-
.....................................................................................................................................................................

This is a special class that can not be inherited.

final class A
{

}

class B extends A  //error because the final can not be inherited
{

}

Note:-  final is the modifier of Java which is used to restrict the variable to override value, restrict method from function overriding, and restrict class for inheritance.


final int a=10;
final void display()
{

}



a final variable can not be overridden, a final method can  not be override and final class can not be inherited




Interface:-

It is a pure abstract class because Interface only contains a set of abstract methods.

but now interface some features have been modified now we can write the default method and static method under the interface.



this feature has been added in JDK 1.8.


The interface not contain any protected, default private dynamic method, and constructor.




It is also used to declare a set of abstract method which will be implemented by the Middle Layer of The project.



Interface Support Multiple Inheritance because we can implement two interfaces in One class.


Syntax of Interface:-


interface Interfacename
{

default void methodName()    #default method
{

}

static void fun()    #static method
{

}


void methdoname();  #abstract method
 

}


no need to write abstract and public keyword, it will be by default public and abstract:-


interface I
{
int a=10;  //final variable
default void methodName()  //default
{
  System.out.println("default");
}

static void fun()  //static
{
System.out.println("fun");
}
void fun1();  //abstract

}



interface I1
{
  void fun2();
}


class A implements I, I1      #multiple inheritance 
{
   public void fun1()
   {
      System.out.println("fun1");
   }
   public void fun2()
   {
      System.out.println("fun2");
   }
  public static void main(String args[])
  {
      I obj = new A();
      obj.methodName();
      I.fun();
      I1 obj1 = new A();
      obj1.fun2();
    
  }

}




Latest Example of Interface and class

interface Area
{
   final int a=10;
   static void fun()
   {
      System.out.println("Static");
   }
   default void fun2()
   {
      System.out.println("default");
   }
   void triangle();
   void rectangle();
}
interface Maths
{
   void multi();
}
class A
{

}
class B
{

}
class Impl extends A implements Area, Maths
{
   public void multi()
  {
    System.out.print("TAREA");
  }
  public void triangle()
  {
    System.out.print("TAREA");
  }
  public void rectangle()
  {
    System.out.print("RAREA");
  }
public static void main(String args[])
  {
     Area obj = new Impl();
     obj.triangle();
     obj.rectangle();
  }
}


Modified Example:-

interface Area
{
   final int a=10;
   static void fun()
   {
      System.out.println("Static");
   }
   default void fun2()
   {
      System.out.println("default");
   }
   void triangle();
   void rectangle();
}
interface Maths extends Area
{
   void multi();
}
abstract class A
{

}
class B
{

}
class Impl extends A implements Maths
{
   public void multi()
  {
    System.out.print("TAREA");
  }
  public void triangle()
  {
    System.out.print("TAREA");
  }
  public void rectangle()
  {
    System.out.print("RAREA");
  }
public static void main(String args[])
  {
     Area obj = new Impl();
     obj.triangle();
     obj.rectangle();
  }
}


Example of Inhertitance:-

interface Idevice
{
   static void deviceInfo()
   {
      System.out.println("Device info");

   }

   default void deviceColor(String color)
   {
     System.out.println("Color is "+color);
   }

 void deviceSpeed();
   

}

interface A extends Idevice
{
    
}
class ISales
{
    void hireTeam()
    {
       System.out.println("hire team");
    }

}
class Mydevice extends ISales implements Idevice
{
 public void deviceMileage()
  {
    System.out.println("Milege");
  }
 public  void deviceSpeed()
  {
    System.out.println("speed");
  }
   public  void hireTeam()
  {
    System.out.println("Sales");
  }
}

class Client
{
   public static void main(String ram[])
  {
        Idevice obj = new Mydevice();
        obj.deviceSpeed();
        Idevice.deviceInfo();
        obj.deviceColor("RED");
        

  }

}

12 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. program of employee

    import java.util.Scanner;
    class Emp
    {
    Scanner sc=new Scanner(System.in);
    int empid,sal;
    String name,job;
    void accept()
    {
    System.out.println("Enter Employee Id");
    empid=sc.nextInt();
    System.out.println("Enter Employee Name");
    name=sc.next();
    System.out.println("Enter Employee Job");
    job=sc.next();
    System.out.println("Enter Employee Salary");
    sal=sc.nextInt();
    }
    void display()
    {
    System.out.println(empid);
    System.out.println(name);
    System.out.println(job);
    System.out.println(sal);
    }
    }
    class Empmain
    {
    public static void main(String args[])
    {
    Emp e=new Emp();
    e.accept();
    e.display();

    }
    }

    ReplyDelete
  2. import java.util.Scanner;
    class Marksheet
    {
    private int roll,ph,ch,eh,mh,total;
    private String name;
    void get(int roll,String name,int ph,int ch,int eh,int mh)
    {
    this.roll=roll;
    this.name=name;
    this.ph=ph;
    this.ch=ch;
    this.eh=eh;
    this.mh=mh;
    total=ph+ch+eh+mh;
    }
    void show()
    {
    System.out.println();
    System.out.println("Roll no = "+roll);
    System.out.println("Name = "+name);
    System.out.println();
    System.out.println("Physics Score= "+ph+"/100");
    System.out.println("Chemistry Score= "+ch+"/100");
    System.out.println("English Score = "+eh+"/100");
    System.out.println("Maths Score = "+mh+"/100");
    System.out.println();
    System.out.println("Total Marks Obtained = "+total+"/400");
    System.out.println();
    }


    }

    class Markmain
    {
    public static void main(String args[])
    {
    int r,x,i,p,c,e,m;
    String nm;
    Scanner sc =new Scanner(System.in);
    System.out.println("Enter number of students = ");
    x=sc.nextInt();
    Marksheet s[] = new Marksheet[x+1];
    for(i=1;i<x+1;i++)
    {
    System.out.println("Enter records for "+i+" student");
    s[i]=new Marksheet();
    System.out.println("Enter roll no = ");
    r=sc.nextInt();
    System.out.println("Enter name = ");
    nm=sc.next();
    System.out.println("Enter Marks in Physics = ");
    p=sc.nextInt();
    System.out.println("Enter Marks in Chemistry = ");
    c=sc.nextInt();
    System.out.println("Enter Marks in English = ");
    e=sc.nextInt();
    System.out.println("Enter Marks in Maths = ");
    m=sc.nextInt();
    s[i].get(r,nm,p,c,e,m);
    }
    for(i=1;i<x+1;i++)
    {
    s[i].show();
    }
    }
    }

    ReplyDelete
  3. CREATE CLASS TO MANAGE EMPLOYEE INFORMATION USING EMPID, EMP NAME, JOB, SALARY

    import java.util.Scanner;

    public class EmployImformation {
    int empid;
    String name;
    float salary;
    void accept()
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the emp id");
    empid =sc.nextInt();
    System.out.println("enter the name");
    name=sc.next();
    System.out.println("enter the Salary");
    salary=sc.nextFloat();
    }
    void display()
    {
    System.out.println("emp id =" + empid);
    System.out.println("emp name =" + name);
    System.out.println("emp salary =" + salary);


    }

    }
    public class EmployImformationMain {

    public static void main(String[] args) {
    EmployImformation obj=new EmployImformation();
    obj.accept();
    obj.display();

    }

    }

    ReplyDelete
  4. MARKSHEET PROGRAM USING FIVE DIFFERENT STUDENT AND FIND MAX
    OBTAINED MARKS.

    import java.util.Scanner;

    public class Marksheet {
    int m1,m2,m3,m4,m5;
    String s1,s2,s3,s4,s5;
    Scanner sc=new Scanner(System.in);
    void calcMarks()
    {
    System.out.println("enter sbject name and marks");
    s1=sc.next();
    m1=sc.nextInt();
    System.out.println("enter subject and marks");
    s2=sc.next();
    m2=sc.nextInt();
    System.out.println("enter subject and marks");
    s3=sc.next();
    m3=sc.nextInt();
    System.out.println("enter subject and marks");
    s4=sc.next();
    m4=sc.nextInt();
    System.out.println("enter subject and marks");
    s5=sc.next();
    m5=sc.nextInt();
    if((m1>=0&&m1<=100)&&(m2>=0&&m2<=100)&&(m3>=0&&m3<=100)&&(m4>=0&&m4<=100)&&(m5>=0&&m5<=100))
    {
    int c=0;
    int mark=0;
    String sub="";
    String dist="";
    if(m1>=75)
    dist+=s1+"";
    if(m2>=75)
    dist+=s2+"";
    if(m3>=75)
    dist+=s3+"";
    if(m4>=75)
    dist+=s4+"";
    if(m5>75)
    dist+=s5+"";

    if(m1<33)
    {
    mark=m1;
    sub+=s1+" ";
    c++;
    }


    if(m2<33)
    {
    sub+=s2+" ";
    mark=m2;
    c++;

    }

    if(m3<33)
    {
    sub+=s3+" ";
    mark=m3;
    c++;
    }


    if(m4<33)
    {
    sub+=s4+" ";
    mark=m4;
    c++;
    }

    if(m5<33)
    {
    sub+=s5+"";
    mark=m5;
    c++;
    }

    if (c==0||(c==1 && mark>=28))
    {
    float res;
    if(c==0)
    res=(m1+m2+m3+m4+m5)/5;
    else
    res=(m1+m2+m3+m4+m5+(33-mark))/5;
    if(res>=33&&res<45)
    System.out.println("pass with third division");
    else if(res<60)
    System.out.println("pass with second division");
    else
    System.out.println("pass with first division");
    if(c==1)
    System.out.println("note:-you are pass by grace and grace mark is" +(33-mark)+"grace subject is "+sub);
    if(dist!="")
    System.out.println("distinction sub name is"+dist);


    }

    else if(c==1)
    System.out.println("try again you are supplementri" +sub);
    else
    System.out.println("sry you have faild" +sub);
    }





    else

    {
    System.out.println("invalid marks");
    }





    }



    public static void main(String[] args) {

    Marksheet obj=new Marksheet();
    obj.calcMarks();
    }

    }


    ReplyDelete
  5. public class Overriding {
    public void boardInfo()
    {
    System.out.println("RGPV");
    }
    public void examPattern()
    {
    System.out.println("Number System");
    }

    }
    class Examnew extends Overriding
    {
    public void examPattern(String s)
    {
    System.out.println("Grade System"+s);
    }
    public void examPattern()
    {
    System.out.println("Grade System");
    }

    public static void main(String args[])
    {

    // Exam obj = new Examnew();
    // Exam obj = new Exam();
    Examnew obj = new Examnew();
    obj.boardInfo();
    obj.examPattern();
    }

    }






    ReplyDelete
  6. # addition program using oops

    import java.util.*;
    class Op
    {
    int a;
    int b;
    int c;


    void num(int a,int b)
    {
    this.a=a;
    this.b=b;
    }

    void add()
    {
    c=a+b;
    System.out.println(c);
    }

    void sub()
    {
    c=a-b;
    System.out.println(c);
    }
    void multi()
    {
    c=a+b;
    System.out.println(c);
    }
    void div()
    {
    c=a+b;
    System.out.println(c);
    }

    }







    import java.util.*;
    class OpR
    {
    public static void main(String arg[])
    {
    Op o=new Op();

    while(true)
    {
    Scanner sc=new Scanner(System.in);
    System.out.print("enter ch");
    char s=sc.next().charAt(0);
    Scanner c=new Scanner(System.in);
    System.out.print("enter number 1"+ " ");
    int a=c.nextInt();
    Scanner c2=new Scanner(System.in);
    System.out.print("enter number 2"+ " ");
    int b=c2.nextInt();
    o.num(a,b);
    if(s=='+')
    {
    o.add();
    }
    if(s=='-')
    {
    o.sub();
    }
    if(s=='*')
    {
    o.multi();
    }
    if(s=='/')
    {
    o.div();
    }
    }
    }
    }

    ReplyDelete
  7. import java.util.Scanner;
    class Marksheet
    {
    int rollno,phno,chno,ehno,mhno,total;
    String suname;
    void getdata()
    {
    this.rollno=rollno;
    this.suname=suname;
    this.phno=phno;
    this.chno=chno;
    this.ehno=ehno;
    this.mhno=mhno;
    total=phno+chno+ehno+mhno;
    }
    void display()
    {

    System.out.println("Roll no = "+rollno);
    System.out.println("Name = "+suname);
    System.out.println("Physics Score= "+phno+"/100");
    System.out.println("Chemistry Score= "+chno+"/100");
    System.out.println("English Score = "+ehno+"/100");
    System.out.println("Maths Score = "+mhno+"/100");
    System.out.println();
    System.out.println("Total Marks Obtained = "+total+"/400");

    }


    }

    public class Main {

    public static void main (String[] args) {
    int rollno,mathno,phyno,engno,cheno,size;
    String suname;

    Scanner sc=new Scanner(System.in);
    System.out.println("how many student");
    size=sc.nextInt();
    Marksheet mark[] =new Marksheet[size];
    for(int i=1;i<size;i++)
    {
    System.out.println("Enter records for "+i+" student");
    mark[i]=new Marksheet();
    System.out.println("Enter roll no = ");
    rollno=sc.nextInt();
    System.out.println("Enter name = ");
    suname=sc.next();
    System.out.println("Enter Marks in Physics = ");
    phyno=sc.nextInt();
    System.out.println("Enter Marks in Chemistry = ");
    cheno=sc.nextInt();
    System.out.println("Enter Marks in English = ");
    engno=sc.nextInt();
    System.out.println("Enter Marks in Maths = ");
    mathno=sc.nextInt();
    mark[i].getdata();
    }
    for(int i=1;i<size;i++)
    {
    mark[i].display();
    }

    }
    }

    ReplyDelete
  8. import java.util.Scanner;
    class Marksheet
    {
    int rollno,phno,chno,ehno,mhno,total;
    String suname;
    void getdata()
    {
    this.rollno=rollno;
    this.suname=suname;
    this.phno=phno;
    this.chno=chno;
    this.ehno=ehno;
    this.mhno=mhno;
    total=phno+chno+ehno+mhno;
    }
    void display()
    {

    System.out.println("Roll no = "+rollno);
    System.out.println("Name = "+suname);
    System.out.println("Physics Score= "+phno+"/100");
    System.out.println("Chemistry Score= "+chno+"/100");
    System.out.println("English Score = "+ehno+"/100");
    System.out.println("Maths Score = "+mhno+"/100");
    System.out.println();
    System.out.println("Total Marks Obtained = "+total+"/400");

    }


    }

    public class Main {

    public static void main (String[] args) {
    int rollno,mathno,phyno,engno,cheno,size;
    String suname;

    Scanner sc=new Scanner(System.in);
    System.out.println("how many student");
    size=sc.nextInt();
    Marksheet mark[] =new Marksheet[size+1];
    for(int i=1;i<size+1;i++)
    {
    System.out.println("Enter records for "+i+" student");
    mark[i]=new Marksheet();
    System.out.println("Enter roll no = ");
    rollno=sc.nextInt();
    System.out.println("Enter name = ");
    suname=sc.next();
    System.out.println("Enter Marks in Physics = ");
    phyno=sc.nextInt();
    System.out.println("Enter Marks in Chemistry = ");
    cheno=sc.nextInt();
    System.out.println("Enter Marks in English = ");
    engno=sc.nextInt();
    System.out.println("Enter Marks in Maths = ");
    mathno=sc.nextInt();
    if(mathno<33)
    {
    System.out.println("you have a supply mantry");
    }
    if(phyno<33)
    {
    System.out.println("better luck next time you are failed ");
    }

    mark[i].getdata();
    }
    for(int i=1;i<size+1;i++)
    {
    mark[i].display();
    }

    }
    }

    ReplyDelete
  9. class BankofIndia
    {
    String custmername,acotype;
    int acono,bal,amt;
    importScanner sc=new Scanner(System.in);

    void BankOfindia( String custmername,String acotype,int acotype,int acono)
    {
    this.custmername=custmername;
    this.acono=acono;
    this.bal=bal;
    this.acotype=acotype;

    }
    int Deposit()
    {
    System.out.println("Enter ammount to deposit");
    amt=sc.nextInt();
    if(amt<0)
    {
    System.out.println("invalid ammount");
    return 1;
    }
    bal=bal+amt;
    return 0;
    }

    int Withdraw()
    {
    System.out.println("your balance is" +bal);
    System.out.println("enter ammount to withdraw");
    amt=sc.nextInt();
    if(bal<amt)
    {
    System.out.println("not suufiecient balance in your account");
    return 1;
    }
    if(amt<0)
    {
    System.out.println("invalid balance");
    return 1;

    }
    bal=bal-amt;
    return 0;
    } void display()
    {
    System.out.println("custmer name: "+custmername);
    System.out.println("Account no: "+acono);
    System.out.println("balance: "+bal);

    }


    }
    public class Main
    {
    public static void main(String[] args) {
    System.out.println("welcome the bankOf India");
    System.out.println("enter your name: "+custmername);
    custmername=sc.next();
    System.out.println("enter your Account no: "+acono);
    acono=sc.nextInt();
    System.out.println("enter your Account type: "+acotype);
    acotype=sc.next();
    System.out.println("enter initial balance: "+bal);
    bal=sc.next();
    BanoOfIndia boi=new BankOfIndia(cusname,anum,actype,bal);
    int menu;
    System.out.println("menu");
    System.out.println("1.Deposit Amount");
    System.out.println("2.Withdraw Amount");
    System.out.println("3.Display Information");
    System.out.println("4.Exit");
    boolean exit=true;
    do
    {
    System.out.println("enter your choice");
    menu=sc.nextInt();
    switch(menu)
    {
    case 1:
    boi.deposit();
    break;
    case 2:
    boi.withdraw;
    break;
    case 3:
    boi.display;
    break;
    case 4:
    exit=true;
    break;
    }
    while(!exit);
    }



    }

    ReplyDelete
  10. import java.util.Scanner;
    class Employe
    {

    int empid,empsal;
    String empname,job;
    void getdata()
    {
    Scanner sc=new Scanner(System.in);

    System.out.println("enter the emplye name");
    empname=sc.next();
    System.out.println("enter ihe employe id");
    empid=sc.nextInt();
    System.out.println("enter the employe salary");
    empsal=sc.nextInt();
    System.out.println("enter the employe job titie");
    job=sc.next();


    }
    void display()
    {
    System.out.println("welcome in our company");
    System.out.println("employe name is: "+ empname);
    System.out.println("your salary is: "+ empsal);
    System.out.println("your id is: " + empid);
    System.out.println("your job title is: " + job);

    }
    }
    class Main
    {
    public static void main(String args[] )
    {
    Employe e[]=new Employe[5];
    for(int i=0;i<5;i++)
    {
    System.out.println("employe record of"+i+"number");
    e[i]=new Employe();
    e[i].getdata();
    }
    for(int i=1;i<5;i++)
    {
    e[i].display();
    }
    }
    }

    ReplyDelete
  11. public class Main
    {
    public static void main(String[] args)
    {
    int a[][]={{1,2,3},{3,3,3},{4,4,4}};
    int b[][]={{1,1,1},{2,2,2},{3,3,3}};
    int c[][]=new int [3][3];
    for(int i=0;i<3;i++)
    {
    for(int j=0;j<3;j++)
    {
    c[i][j]=0;
    for(int k=0;k<3;k++)
    {
    c[i][j]=a[i][k]*b[k][j]+c[i][j];
    System.out.print(c[i][j]+" ");
    }
    System.out.println();
    }

    }
    }

    }

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post