标签:
class Book{
private String title ;
private double price ;
public Book(String title , double price ){
this.title = title ;
this.price = price ;
}
public boolean Compare(Book book){
if(this == book )
return true ;
if(book == null)
return false ;
if(this.title.equals(book.title) && this.price == book.price) //可以直接 访问 私有成员变量
return true ;
else
return false ;
}
}
public class Test{
public static void main(String args[]){
Book b1 = new Book("java",19.9) ;
Book b2 = new Book("c",19.9) ;
if(b1.Compare(b1))
System.out.println("1") ;
else
System.out.println("0") ;
}
}
标签:
原文地址:http://www.cnblogs.com/da-peng/p/5118722.html