标签:print return class oat 构造方法 构造 str bsp color
/*
功能:Java"封装"的典型例子
*/
public class Demo3_5
{
public static void main(String args[]){
Clerk clerk1=new Clerk("qingfeng",22,5321.12f);
System.out.println("名字为"+clerk1.name+"薪资为"+clerk1.getSalary());//只能通过授权的操作(成员方法)进行访问
}
}
class Clerk
{
public String name ;
private int age;
private float salary;
//构造方法
public Clerk(String name, int age, float sal){
this.name = name;
this.age = age;
this.salary = sal;
}
//成员方法
public float getSalary(){
return this.salary;
}
}
标签:print return class oat 构造方法 构造 str bsp color
原文地址:http://www.cnblogs.com/qingfengzhuimeng/p/6418734.html