My Beautiful Crafted Java OOP

Human.java

package com.zakilive;

public class Human {

    String name;
    int age;
    int heightInInches;
    String eyeColor;

    public Human(String name,int age,int heightInInches,String eyeColor){ //special method/construcotr method same name as class, constructor has no return type
        this.age=age;   //this is a variable which is making it dynamic when it puts
        this.heightInInches=heightInInches;
        this.eyeColor=eyeColor;
        this.name=name;
    }

    public void Speak(){
        System.out.println("Hello, my name is "+name);
        System.out.println("I am "+heightInInches+" inches tall");
        System.out.println("I am "+age+" years old");
        System.out.println("My eye color is "+eyeColor);
        System.out.println("\n");
    }

    public void eat(){
        System.out.println("Eating...");
    }

    public void walk(){
        System.out.println("Walking...");
    }

    public void work(){
        System.out.println("Working....");
    }

}

Earth.java

package com.zakilive;

public class Earth {
    public static void main(String[] args)
    {
       Human human1=new Human("Togo",23,67,"Blue");
       Human human2=new Human("Bogo",32,7,"BlueOcean");
       Human human3=new Human("Zogo",34,889,"purple");

       human1.Speak();
       human2.Speak();
       human3.Speak();
    }
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.