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

BookDemo1b Java

The document contains a Java program that defines a class 'BookDemo1b' with multiple constructors: a default constructor, a parameterized constructor, and a copy constructor. It initializes book details such as title, author, and price, and includes a method to display these details. The main method demonstrates the creation of book objects using each constructor type and displays their information.

Uploaded by

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

BookDemo1b Java

The document contains a Java program that defines a class 'BookDemo1b' with multiple constructors: a default constructor, a parameterized constructor, and a copy constructor. It initializes book details such as title, author, and price, and includes a method to display these details. The main method demonstrates the creation of book objects using each constructor type and displays their information.

Uploaded by

Sonu Jadhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Generated by: Java Viewer

package constructor;

public class BookDemo1b {

public static void main(String[] args) {

String title;
String author;
double price;
}

BookDemo1b(){
title="Unknown";
author="Unknown";
price=0.0;
}

BookDemo1b(String t,String a,double p){


title=t;
author=a;
price=-p;
}

BookDemo1b(BookDemo1 b){
title=[Link];
author=[Link];
price=[Link];
}

void display() {
[Link]("Title:"+title);
[Link]("Author:"+author);
[Link]("Price:"+price);
[Link]("----------------");
}
}
public class BookDemo1b {
public static void main(String[]args) {
Book b1=new Book();
[Link]("Book 1 Details (Default Constructor):");
[Link]();

Book b2=new Book("Java Programing","James Gosling",550.0);


[Link]("Book 2 Details(Parameterized Constructor):");
[Link]();
Book b3 = new Book(b2);
[Link]("Book 3 Details (Copy Constructor):");
[Link]();
}
}

You might also like