-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrarySystem.java
More file actions
60 lines (53 loc) · 1.63 KB
/
LibrarySystem.java
File metadata and controls
60 lines (53 loc) · 1.63 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Book {
// Static variable
private static String libraryName = "City Library";
// Instance Variable
private final String isbn; // Final variable (cannot be changed)
private String title;
private String author;
// Constructor
Book(String isbn, String title, String author) {
this.isbn = isbn;
this.title = title;
this.author = author;
}
// Method to display book details
public void displayDetails() {
if(this instanceof Book) { // Using instanceOf
System.out.println("Library Name: " + libraryName);
System.out.println("ISBN: " + isbn);
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println();
}
}
// Method to display library name
public static void getLibraryName() {
System.out.println("Library Name: " + libraryName);
}
}
// Main Class
public class LibrarySystem {
public static void main(String[] args) {
// Create Objects of Book class
Book book1 = new Book("978-3-16-148410-0", "Java Programming", "RK Singh");
Book book2 = new Book("978-0-262-13472-9", "Data Structures", "SP Shukla");
// Display book details
book1.displayDetails();
book2.displayDetails();
// Display library name
Book.getLibraryName();
}
}
// Sample Output ->
//Library Name: City Library
//ISBN: 978-3-16-148410-0
//Title: Java Programming
//Author: RK Singh
//
//Library Name: City Library
//ISBN: 978-0-262-13472-9
//Title: Data Structures
//Author: SP Shukla
//
//Library Name: City Library