首页上一页 1 下一页尾页 1 条记录 1/1页
权限修饰符
发表在Java图书答疑
2014-11-12
是否精华
是
否
版块置顶:
是
否
class Book{
private String title; //定义书名
private String author; //定义作者
private double price; //定义价格
public Book(String title,String author,double price){ //利用构造方法初始化域
this.title=title;
this.author=author;
this.price=price;
}
public String getTitle(){ //获取书名
return title;
}
public String getAuthor(){ //获取作者
return author;
}
public double getPrice(){ //获取价格
return price;
}
}
public class dongjing {
public static void main(String[] args) {
// TODO 自动生成
Book book=new Book("《Java从入门到精通》","明日科技",59.8); //创建对象(将Book类实例化)
System.out.println("书名:"+book.getTitle()); //输出书名
System.out.println("作者:"+book.getAuthor()); //输出作者
System.out.println("价格:"+book.getPrice()); //输出价格
}
}
这个程序class Book前面加修饰符public后提示编译失败,是为什么。
private String title; //定义书名
private String author; //定义作者
private double price; //定义价格
public Book(String title,String author,double price){ //利用构造方法初始化域
this.title=title;
this.author=author;
this.price=price;
}
public String getTitle(){ //获取书名
return title;
}
public String getAuthor(){ //获取作者
return author;
}
public double getPrice(){ //获取价格
return price;
}
}
public class dongjing {
public static void main(String[] args) {
// TODO 自动生成
Book book=new Book("《Java从入门到精通》","明日科技",59.8); //创建对象(将Book类实例化)
System.out.println("书名:"+book.getTitle()); //输出书名
System.out.println("作者:"+book.getAuthor()); //输出作者
System.out.println("价格:"+book.getPrice()); //输出价格
}
}
这个程序class Book前面加修饰符public后提示编译失败,是为什么。