practice-program-1

Create a class containing three variables and also make constructors for all the available variable?


public class human 
{
    public int age;
    public String name;
    public String gender;

     public human() {
        this.age = 0;
        this.name = "";
        this.gender = "";
    }
    public human(int age) {
        this.age = age;
        this.name = "";
        this.gender = "";
    }
     public human(int age, String name) {
        this.age = age;
        this.name = name;
        this.gender = "";
    }
      public human(int age, String name, String gender) {
        this.age = age;
        this.name = name;
        this.gender = gender;
    }
     
    public static void main(String args[])
    {
        human obj=new human();
        human obj1=new human(3);
        human obj2=new human(3,"Ali");
        human obj3=new human(3,"Ali","male");
        
    }
    
}

Previous Lecture                                                                                                                    Next lecture