import java.util.*;

public class BookTest
{
public static void main(String[] args)
{
//Book book = new Book("A Tale of Two Cities", 1895);
Book book = new Book("A Tale of Two Cities");
System.out.println(book.title);
System.out.println(book.pubYear);
System.out.println(Book.count);
Book book2 = new Book("War and Peace");
System.out.println(Book.count); // count 是静态变量,新建book2实类后自动+1
}
} class Book
{
String title;
int pubYear;
static int count = 0;
public Book(String title)
{
this(title, -1); //如果没有接收到第二个变量,pubYear自动设为1
} public Book(String title, int pubYear)
{
setTitle(title);
setPubYear(pubYear);
++count;
}
public void setTitle(String title)
{
this.title = title;
} public void setPubYear(int pubYear)
{
this.pubYear = pubYear;
} }

最新文章

  1. Java-Android【1】-控制手机震动
  2. SQL Server2008 表旋转(pivot)技术
  3. 使用Atlas实现MySQL读写分离
  4. 《OpenCV入门》(三)
  5. Object Pascal 语法之异常处理
  6. Objective-C的对象模型和runtime机制
  7. BestCoder Round #68 (div.2) 1002 tree
  8. An error occurred while filtering resources
  9. Linux下创建、查看、提取和修改静态库(*.a)
  10. spring xml记录
  11. 开心系列学习笔记---------javascript(7)
  12. NET Core开发-使用Nancy框架
  13. 控制执行流程——(Java学习笔记三)
  14. LeetCode Weekly Contest
  15. Akka(8): 分布式运算:Remoting-远程查找式
  16. Hive入门教程
  17. c中有序表的简单定义
  18. vue实现打印功能的两种方法
  19. 【Diary】期中考+春游记
  20. oracle 数据库去重复数据

热门文章

  1. "sorted()"中的"Key Functions"
  2. JavaWeb(六):会话与状态管理
  3. 【leetcode】336. Palindrome Pairs
  4. leetcode-167周赛-1291-顺次数
  5. DELPHI FMX IOS模拟器调试时出现No SDKs could be found
  6. 【HDOJ6606】Distribution of books(二分,BIT)
  7. 转载:IDEA lombok插件的安装和使用
  8. 北风设计模式课程---20、UML类图介绍
  9. DB-概念-同义词:同义词/Synonym
  10. Chrome-逆向分析JS-2获取发送请求位置(以datatables获取表格数据为例)