Q:

HW class and object in java

0

1. Giving the following Java program representing the class student, complete the missing code.

a.     Getter and setter

b.     Constructors

2. in the main,

Create an array of employees AR-EMP

Add to AR-EMP  2 employees E1 :( “Mohamed”, 1) and E2 :( “Ali”, 2)

Copy the first array of students AR-EMP in a second array ARE_copy.

 public class EMP {

 

    private String name;  //INATANCE

    private int age;

    static int nbe=0; //the number of instance created

 

     Getter and setter

     Constructor no-arg

    Constructors with parameters

    Copy Constructors

          

     public static void main(String[] args) {

    

     }

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Getter and setter

public string getname(){ return name;}

Public void setname(string name){this.name=name;}

Public int getage(){return age ;}

Public void setage(int age){this.age=age;}

/Constructor no-arg

Public emp(){nbe++;}

/Constructor with par

Public EMP(string name, int age){

This.name=name;

This.age=age;

npe++;} 

 

 

/Copy intsructor

Puplic EMP(EMP emp){

This.name=empname;

This.age=empage;npe++}

public static  void main (string[] args){

EMP[] AR_EMP=new EMP[2]

EMP e1=new EMP("mohamed", 1);

EMP e2=new EMP("ali",2)

AR_EMP[0]=E1;

AR_EMP[1]=E2;}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now