- public class B {
- public static void main(String[] args) {
- Family man=new Family("Father", 40, "mountain climbing");
- Family woman=new Family("Mother", 38, "shopping");
- Family boy=new Family("Boy", 10, "gaming");
- Family girl=new Family("Girl", 8, "reading");
- man.showProfile();
- woman.showProfile();
- boy.showProfile();
- girl.showProfile();
- }
- }
- class Family
- {
- String name, hobby;
- int age;
- Family(String n,int a, String h)
- {
- name=n;
- age=a;
- hobby=h;
- }
-
- void showProfile()
- {
- System.out.println(name+", "+age+" years, enjoys "+hobby);
- }
- }
複製代碼 |