Q:

What is the output of the following program? Class Definition and set & get Methods

0

What is the output of the following program? Class Definition and set & get Methods

class Book
{
  private String bookName;
  private double bookPrice;

  public void setBookName(String bookName)
  {
    this.bookName = bookName;
  }
  public void setBookPrice(double bookPrice)
  {
    this.bookPrice = bookPrice;
  }
  public void setBook(String bookName, double bookPrice)
  {
    this.bookName  = bookName;
    this.bookPrice = bookPrice;
  }
  public String getName()
  {
    return bookName;
  }
  public double getPrice()
  {
    return bookPrice;
  }
  public void show()
  {
    System.out.println("Book Name: " + bookName + "\n" +
                       "Book Price: " + bookPrice);
  }
}

public class TestBook
{
  public static void main( String[] args )
  {
     Book book1 = new Book();
     Book book2 = new Book();
     
     book1.setBookName ("Java How to Program");
     book1.setBookPrice(240.0);
     book2.setBookName ("Introduction to Java");
     book2.setBookPrice(193.0);
     book1.setBook( book2.getName(), book1.getPrice()+5 );
     book2.setBook( book1.getName(), book2.getPrice()-5 );
     book1.show();
     book2.show();
  }
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Book Name: Introduction to Java

Book Price: 245.0

Book Name: Introduction to Java

Book Price: 188.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

implement class Car using java OOP... >>
<< Write a Java program that define class Rectangle w...