Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Book {
- private int year;
- private String name;
- public Book(String n, int y){
- year = y;
- name = n;
- }
- public Book(String n){
- name = n;
- year = 0;
- }
- public Book(){
- name = "Demian";
- year = 0;
- }
- public void setName(String name){
- this.name = name;
- }
- public void setYear(int year){
- this.year = year;
- }
- public String getName(){
- return name;
- }
- public int getYear(){
- return year;
- }
- public String toString(){
- return this.name+"'s age is "+this.year;
- }
- }
- public class TestBook {
- public static void main(String[] args) {
- Book book1 = new Book("Night in the Lissabone", 1941);
- Book book2 = new Book("Three comrades");
- Book book3 = new Book();
- book3.setName("Harry Potter");
- book3.setYear(1997);
- book3.getName();
- System.out.println(book3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement