QN037. Create object of book class with calling parameterized constructor and print information.
1. Objective
To create an object of book class with calling parameterized constructor.
2. Theory
A constructor is called paramaterized constructor when it accepts a specific number of parameters. It is used to provide different values to distinct objects. However, we can provide the same values also.
3. Source Code
      public class Qn037{ 
      String bookName;
      String author;
      int price;
      Qn037(String bookName, String author, int price){
        this.bookName = bookName;
        this.author = author;
        this.price = price;
      }
      void infoDisplay(){
        System.out.println("Book Name: " + bookName); 
        System.out.println("Book Author: " + author); 
        System.out.println("Book Price: " + price); 
      }
      public static void main(String[] args){
        Qn037 b = new Qn037("JAVA","Sajan Kc",555);
        b.infoDisplay();
      }
    }
    
    4. Output
    Book Name: Java 
    Book Author: Sajan Kc 
    Book Price: 555 
    
5. Conclusion
In this way, I would like to conclude that, we can pass different arguments using parametrized constructor, do calculations and display values.