Java Program For Has-A Relation

Free Java courses with 37 real-time projects - Learn Java

Program 1

package emp;

public class EmpInfo 
{
    PersonalInfo P;
    int empid;
    String DeptName;
    int Salary;

    public EmpInfo(PersonalInfo P, int empid, String DeptName, int Salary) 
    {
        this.P = P;
        this.empid = empid;
        this.DeptName = DeptName;
        this.Salary = Salary;
    }
   public void display()    
   {
       System.out.println("Name: "+P.name);  
       System.out.println("Address: "+P.address);  
       System.out.println("Mobile No: "+P.mobileno);  
       System.out.println("Emp Id: "+this.empid);
       System.out.println("Department Name: "+this.DeptName);
       System.out.println("Salary: "+this.Salary);
   }
    
}

Program 2

package emp;

public class TestMain 
{
    public static void main(String[] args) 
    {
        PersonalInfo P=new PersonalInfo("Rajesh More","Abc Colony Mumbai",123456);
         EmpInfo E=new EmpInfo(P,101,"CSE",90000);
         E.display();
    }
    
}

Program 3

package emp;

public class PersonalInfo 
{
     String name;
     String address;
     int mobileno;

    public PersonalInfo(String name, String address, int mobileno) 
    {
        this.name = name;
        this.address = address;
        this.mobileno = mobileno;
    }
     
    
}

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *