-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram1.java
More file actions
38 lines (34 loc) · 1.01 KB
/
program1.java
File metadata and controls
38 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class program1 {
public static void main(String[] args) {
// Using the full constructor
Book book1 = new Book("The Great Gatsby", "F. Scott Fitzgerald", 1925, 15.99);
// Using the overloaded constructor
Book book2 = new Book("To Kill a Mockingbird", "Harper Lee");
// Displaying book information
book1.displayBookInfo();
book2.displayBookInfo();
}
}
class Book{
String title,author;
int year;
double price;
Book(String title, String author){
this.title = title;
this.author = author;
this.year = 2000; // Default value
this.price = 10.0;
}
Book(String title,String author,int year,double price){
this.title =title ;
this.author =author ;
this.year =year ;
this.price =price ;
}
public void displayBookInfo(){
System.out.println(title);
System.out.println(author);
System.out.println(year);
System.out.println(price);
}
}