0% found this document useful (0 votes)
10 views2 pages

First

Uploaded by

ksaryan08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

First

Uploaded by

ksaryan08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class first {

public static void main(String[] args) {

FictionBook fictionBook = new FictionBook("The", "ABC", "Comedy");


NonFictionBook nonFictionBook = new NonFictionBook("JAVA", "SAM", "Computer
Science");

System.out.println("Library Management System");


System.out.println("--------------------------");

fictionBook.displayInfo();
fictionBook.displayGenre();

System.out.println();

nonFictionBook.displayInfo();
nonFictionBook.displaySubject();
}
}

class Book {
private String title;
private String author;

public Book(String title, String author) {


this.title = title;
this.author = author;
}

public void displayInfo() {


System.out.println("Title: " + title + ", Author: " + author);
}
}

class FictionBook extends Book {


private String genre;

public FictionBook(String title, String author, String genre) {


super(title, author);
this.genre = genre;
}

public void displayGenre() {


System.out.println("Genre: " + genre);
System.out.println("Type: Fiction");
}
}

class NonFictionBook extends Book {


private String subject;

public NonFictionBook(String title, String author, String subject) {


super(title, author);
this.subject = subject;
}

public void displaySubject() {


System.out.println("Subject: " + subject);
System.out.println("Type: Non-Fiction");
}
}

You might also like