Menu
Question Index
...

Define Book class with multiple constructors such that the program compiles and runs without any error.



class BookWithMultipleConstructors
{
    public static void main(String s[])
    {
        Book book1 = new Book("Java, The Complete Reference");
        Book book2 = new Book("Java, The Complete Reference", "Herbert Schildt");
        Book book3 = new Book("Java, The Complete Reference", "Herbert Schildt", 8);
        
        System.out.println("Book 1 = " + book1.name);
        System.out.println("Book 2 = " + book2.name + " - " + book2.author);
        System.out.println("Book 3 = " + book3.name + " - " + book3.author + " - " + book3.edition);

    }



}
class Book
{
    String name;
    String author;
    int edition;
}

Doubts

Problems

Topic: Class With Multiple Constructors In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App