Click here to watch in Youtube :
https://www.youtube.com/watch?v=pl-G-4q71No&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : What is an Object[Student]? |
Java Tutorial : What is an Object[Student]? |
/** * Student class is the blueprint from which individual student objects can be * created. */ public class Student { String name; int age; String color; String sex; public void eating(String string) { System.out.println(name + " "+ string); } public void drinking(String string) { System.out.println(name + " "+ string); } public void running(String string) { System.out.println(name + " "+ string); } }
public class StudentDemo { public static void main(String[] args) { Student peter = new Student(); /* * Setting States/Attributes/Properties/Characteristics. */ peter.name = "Peter"; peter.age = 3; peter.color = "white"; peter.sex = "male"; displayStudentInformation(peter); System.out.println("\nBehaviors"); System.out.println("----------"); peter.eating("can eat more foods"); peter.drinking("can drink more water"); peter.running("can run fast"); System.out.println("*********************************************"); Student john = new Student(); /* * Setting States/Attributes/Properties/Characteristics. */ john.name = "John"; john.age = 4; john.color = "brown"; john.sex = "male"; displayStudentInformation(john); System.out.println("\nBehaviors"); System.out.println("----------"); john.eating("can eat less foods"); john.drinking("can drink more water"); john.running("can run slow"); System.out.println("*********************************************"); Student julia = new Student(); /* * Setting States/Attributes/Properties/Characteristics. */ julia.name = "Julia"; julia.age = 2; julia.color = "white"; julia.sex = "female"; displayStudentInformation(julia); System.out.println("\nBehaviors"); System.out.println("----------"); julia.eating("can eat less foods"); julia.drinking("can drink less water"); julia.running("can run fast"); System.out.println("*********************************************"); } private static void displayStudentInformation(Student student) { System.out.println("Attributes"); System.out.println("--------------"); System.out.println("Name : " + student.name); System.out.println("Age : " + student.age); System.out.println("Color : " + student.color); System.out.println("sex : " + student.sex); } }
Attributes -------------- Name : Peter Age : 3 Color : white sex : male Behaviors ---------- Peter can eat more foods Peter can drink more water Peter can run fast ********************************************* Attributes -------------- Name : John Age : 4 Color : brown sex : male Behaviors ---------- John can eat less foods John can drink more water John can run slow ********************************************* Attributes -------------- Name : Julia Age : 2 Color : white sex : female Behaviors ---------- Julia can eat less foods Julia can drink less water Julia can run fast *********************************************
https://sites.google.com/site/javaee4321/java/StudentDemoObjectApp.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment