Java中的类也是一种构造数据类型,但是进行了一些扩展,类的成员不但可以是变量,还可以是函数;通过类定义出来的变量也有特定的称呼,叫做“对象”。例如:
package com.company; public class Demo { public static void main(String[] args) { class Student{ String name; int age ; float score ; void say() { System.out.println(name+"的年龄是 "+age+" ,成绩是"+score); } } Student st= new Student(); st.name="丁丁"; st.age=28; st.score=99.5f; st.say(); } }
运行结果
丁丁的年龄是 28 ,成绩是99.5
你打算打赏多少钱呢?

(微信扫一扫)