1 package 面向对象编程_封装性; 2 //1.类名称必须存在有意义,例如Book、Emp 3 //2.类之中所有的属性必须用private封装,封装后的属性必须提供有setter和getter方法 4 //3.类之中可以提供有多个构造方法,但是必须保留有一个无参构造方法 5 //4.类之中不允许出现任何的输出语句,所有信息输出必须交给被调用处输出 6 //5.类之中需要提供有一个取得对象完整信息的方法,暂定为:getInfo ; 返回String数据 7 8 /** 9 * Created by Administrator on 2017/6/26. 10 */ 11 12 class Book_demo{ 13 private String title ; 14 private double money; 15 16 public Book_demo(){} 17 public Book_demo(String t,double m){ 18 title = t; 19 money = m; 20 } 21 22 public void setTitle(String t){ 23 title = t; 24 } 25 public void setMoney(double m){ 26 money = m; 27 } 28 29 public double getMoney() { 30 return money; 31 } 32 33 public String getTitle() { 34 return title; 35 } 36 public String getInfo(){ 37 return "名称:" + title + " "+ 38 "价格:" + money + " "; 39 } 40 } 41 42 public class 简单java类 { 43 public static void main(String[] args) { 44 Book_demo book = new Book_demo("java开发",66.6); 45 book.setTitle("python开发"); // 具备修改 46 System.out.println(book.getInfo()); 47 System.out.println(book.getTitle()); 48 49 } 50 }