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

Stringoperations Java

The document presents a Java class named 'Book' with three constructors: a default constructor, a parameterized constructor, and a copy constructor. It includes a method to display the book's details and demonstrates the creation of three book instances with varying constructors. The output shows the details of each book instance created.

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 views3 pages

Stringoperations Java

The document presents a Java class named 'Book' with three constructors: a default constructor, a parameterized constructor, and a copy constructor. It includes a method to display the book's details and demonstrates the creation of three book instances with varying constructors. The output shows the details of each book instance created.

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

class Book {

String title;
String author;
double price;

Book() {

title = "Unknown";
author = "Unknown";
price = 0.0;

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

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

Book(Book b) {

title = [Link];
author = [Link];
price = [Link];

void display() {

[Link]("Title: " + title);

[Link]("Author: " + author);


[Link]("Price: " + price);

[Link]("---------------------");

public static void main(String[] args) {

Book b1 = new Book();

[Link]("Book 1 Details (Default Constructor):");

[Link]();

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

[Link]("Book 2 Details (Parameterized Constructor):");

[Link]();

Book b3 = new Book(b2);

[Link]("Book 3 Details (Copy Constructor):");

[Link]();

~ output
Book 1 Details (Default Constructor):
Title: Unknown
Author: Unknown
Price: 0.0
---------------------

Book 2 Details (Parameterized Constructor):


Title: Java Programming
Author: James Gosling
Price: 550.0
---------------------

Book 3 Details (Copy Constructor):


Title: Java Programming
Author: James Gosling
Price: 550.0
---------------------

You might also like