Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Constructor


class MyMainEmployee{
    private int id;
    private String name;

    public MyMainEmployee(){
        id = 0;
        name = "Your-Name-Here";
    }
    public MyMainEmployee(String myName, int myId){
        id = myId;
        name = myName;
    }
    public MyMainEmployee(String myName){
        id = 1;
        name = myName;
    }
    public String getName(){
        return name;
    }
    public void setName(String n){
        this.name = n;
    }
    public void setId(int i){
        this.id = i;
    }
    public int getId(){
        return id;
    }
}

public class cwh_42_constructors {
    public static void main(String[] args) {
        //MyMainEmployee d = new MyMainEmployee("ProgrammingWithHarry", 12);
        MyMainEmployee d = new MyMainEmployee();
        //d.setName("Learn java");
        //d.setId(34);
        System.out.println(d.getId());
        System.out.println(d.getName());
    }
}
Source by www.codewithharry.com #
 
PREVIOUS NEXT
Tagged: #Constructor
ADD COMMENT
Topic
Name
8+9 =