Student.java
public class Student {
int age;
//字符串用String,字符数组用char;
String name;
String address;
String tel;
void sayHello(){
System.out.println("age = " + age);
System.out.println("name = " + name);
System.out.println("address = " + address);
System.out.println("tel = " + tel);
}
int add(int num1,int num2){
int r = num1 + num2;
return r;
}
}
TestStudent.java
public class TestStudent {
public static void main(String[] args) {
//Java中没有指针,但Java底层封装指针
//本质上是C++创建的第二种方法
Student zhangsan = new Student();
//对象名.属性名访问属性
//对象名.方法名调用方法
zhangsan.age = 20;
zhangsan.name = "zhangsan";
zhangsan.tel ="110";
zhangsan.address = "huxian";
zhangsan.sayHello();
int r = zhangsan.add(1,2);
System.out.println("r = " + r);
}
}