1 Public class Car {2 String color; 3 String Pinpai; 4 Double size; 5 }
1 class Dianfanbao {2 String Pinpai; 3 Double Daxiao; 4 String color; 5 }
1 class Student {2 String name; 3 int Age ; 4 String sex; 5 }
1 classZonghe {2 Public Static voidMain (string[] args) {3Student Stu =Newstudent ();4Stu.name = "Zhang San";5Stu.age = 13;6Stu.sex = "Male"; 7Dianfanbao DFB =NewDianfanbao ();8Dfb.pinpai = "Nine Yang";9Dfb.daxiao = 1.8;TenDfb.color = "Red"; OneCar CA =Newcar (); ACa.pinpai = "Volkswagen"; -Ca.color = "BLACK"; -Ca.size = 18; theSystem.out.println ("The Student's sex is:" +stu.sex); -SYSTEM.OUT.PRINTLN ("Student's name is:" +stu.name); -SYSTEM.OUT.PRINTLN ("Student's age is:" +stu.age); -System.out.println ("The brand of the car is:" +Ca.pinpai); +SYSTEM.OUT.PRINTLN ("The color of the car is:" +ca.color); -System.out.println ("The size of the car is:" +ca.size); +System.out.println ("Rice Cooker Brand:" +Dfb.pinpai); ASystem.out.println ("Rice Cooker Size:" +Dfb.daxiao); atSystem.out.println ("Rice Cooker Color:" +dfb.color); - } -}
The above example encapsulates 3 classes and then incoming the value in a main method and calls it, because the class that we create ourselves is in the same folder, so there is no import package, and if you call a Java-provided class, you need to import the package and then call it.
Java Reference Data Type instance