image.png

    1. Student类页面
    2. package com.pln.method;
    3. //学习类
    4. public class Student {
    5. // 属性
    6. String name ;
    7. int age;
    8. // 方法
    9. public void student(){
    10. System.out.println(this.name+"在学习,年龄:"+this.age);
    11. }
    12. }
    1. Main类主页面main方法
    2. package com.pln.method;
    3. public class Mains {
    4. public static void main(String[] args) {
    5. // 类:抽象的,实例化
    6. // 类实例化之后返回一个自己的对象
    7. // student对象就是Student类的具体示例
    8. Student xiaoming = new Student();//实例化类队形
    9. Student xiaohong = new Student();
    10. xiaoming.name = "pln"; //给学习类赋值
    11. xiaoming.age = 10;
    12. System.out.println(xiaoming.name);
    13. xiaohong.name = "小红";
    14. xiaohong.age = 20;
    15. System.out.println(xiaohong.age+xiaohong.name);
    16. xiaoming.student(); // 调用学习类中的方法
    17. }
    18. }