什么是面向对象
面向对象的本质就是:以类的方式组织代码,以对象的组织(封装)数据
package com
.etc
.ood
;
public class Student {
String name
;
int age
;
public void study(){
System
.out
.println(this.name
+"在学习");
}
}
package com
.etc
.ood
;
public class Application {
public static void main(String
[] args
) {
Student xiaoming
= new Student();
xiaoming
.name
= "xiaoming";
xiaoming
.age
= 20;
System
.out
.println(xiaoming
.name
+"在学习");
System
.out
.println("今年"+xiaoming
.age
+"岁");
}
}
转载请注明原文地址: https://lol.8miu.com/read-18964.html