class Book
{
//m_name只在本类中有效
private String m_name = "张三";
//定义一个public 方法
public String getM_name() {
return m_name;
}
public void setM_name(String m_name) {
this.m_name = m_name;
}
}
public class PrivateDemo
{
public static void main(String[] args) throws Exception
{
Book b1 = new Book();
//调用public 方法,访问private 变量
String m_name1 = b1.getM_name();
System.out.println(m_name1);