Class
Object
– Earth is a software application where human and other thing is software objects.For creating object we need to create a human class. Humans have basic behaviors as well as some basic attributes age height inches etc.
Human,java
package Prerequisite_OOP;
public class Human {
String name;
int age;
int heightInInches;
String eyeColor;
public Human(){
}
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);
}
public void eat(){
System.out.println("Eating...");
}
public void walk(){
System.out.println("Walking...");
}
public void work(){
System.out.println("Working");
}
}
Earth.java
package Prerequisite_OOP;
public class Earth {
public static void main(String[] args) {
Human tom;
tom=new Human();
tom.speak();
tom.age=5;
tom.eyeColor="Blue";
tom.heightInInches=72;
tom.name="Tom Zsabo";
tom.speak();
}
}