面向对象
类的创建
package com. itheima;
public class Phone {
String brand;
int price;
public void call ( ) {
System. out. println ( "打电话" ) ;
}
public void sendMessage ( ) {
System. out. println ( "发短信" ) ;
}
}
学生对象
package com. itheima;
public class Student {
String name;
int age;
public void study ( ) {
System. out. println ( "好好学习,天天向上" ) ;
} public void doHomeWork ( ) {
System. out. println ( "键盘敲烂,月薪过万" ) ;
}
}
package com. itheima;
public class StudentsDemo {
public static void main ( String[ ] args) {
Student s = new Student ( ) ;
System. out. println ( s. name+ "," + s. age) ;
s. name= "具晟彬" ;
s. age= 24 ;
System. out. println ( s. name+ "," + s. age+ "," + "恭送鼠王" ) ;
s. study ( ) ;
s. doHomeWork ( ) ;
}
}
多个对象
package com. itheima;
public class StudentsDemo1 {
public static void main ( String[ ] args) {
Student s = new Student ( ) ;
System. out. println ( s. name+ "," + s. age) ;
s. name= "具晟彬" ;
s. age= 24 ;
System. out. println ( s. name+ "," + s. age+ "," + "恭送鼠王" ) ;
s. study ( ) ;
s. doHomeWork ( ) ;
Student s1 =</