Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
5
Indexable
Never
public class Book {
    private String title;
    private int numberOfPages;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getNumberOfPages() {
        return numberOfPages;
    }

    public void setNumberOfPages(int numberOfPages) {
        this.numberOfPages = numberOfPages;
    }
}

public class Textbook extends Book {
    private int gradeLevel;

    public int getGradeLevel() {
        return gradeLevel;
    }

    public void setGradeLevel(int gradeLevel) {
        this.gradeLevel = gradeLevel;
    }
}


public class DemoBook {
    public static void main(String[] args) {
        // Creating a Book object
        Book book = new Book();
        book.setTitle("The Great Gatsby");
        book.setNumberOfPages(180);

        // Creating a Textbook object
        Textbook textbook = new Textbook();
        textbook.setTitle("Mathematics for Beginners");
        textbook.setNumberOfPages(300);
        textbook.setGradeLevel(8);

        // Displaying book details
        System.out.println("Book Title: " + book.getTitle());
        System.out.println("Number of Pages: " + book.getNumberOfPages());

        // Displaying textbook details
        System.out.println("Textbook Title: " + textbook.getTitle());
        System.out.println("Number of Pages: " + textbook.getNumberOfPages());
        System.out.println("Grade Level: " + textbook.getGradeLevel());
    }
}