package day06;
public class Demo_01 {
public static void main(String[]args){
//创建对象的格式:类名 对象名 = new 类名();
Student student = new Student();
student.name="张三";//使用成员变量
student.Age=23;//使用成员变量
System.out.println(student.name+"的年龄是:"+student.Age);
student.sleep();//使用成员方法
student.study();//使用成员方法
}
}
//=============================================================
class Student{
//定义学生的属性
String name;
int Age;
String gender;
public void study(){
//定义学习的方法
System.out.println("学生学习");
}
public void sleep(){
//定义睡觉的方法
System.out.println("学生睡觉");
}
}
//==============================================================
class Phone{
//定义手机的属性
String brand;
int price;
public void call(){
System.out.println("打电话");
}
public void sendMessage(){
System.out.println("发信息");
}
public void playGame(){
System.out.println("玩游戏");
}
}
java:面向对象的定义及使用
猜你喜欢
转载自blog.csdn.net/qq_24644517/article/details/81634224
今日推荐
周排行