-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryInheritance.java
More file actions
76 lines (73 loc) · 2 KB
/
LibraryInheritance.java
File metadata and controls
76 lines (73 loc) · 2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.ArrayList;
import java.util.List;
abstract class Publication
{
public int noOfPages;
public float price;
public String publisherName;
publication(int noOfPages,float price,String PublisherName)
{ this.noOfPages=noOfPages;
this.price=price;
this.PublisherName=PublisherName;
}
}
public class Book extends Publication
{
Book(int noOfPages,float price,String publication)
{
super(noOfPages,price,Publishername);
}
}
public class Journal extends Publication
{
Journal(int noOfPages,float price,String publication)
{
super(noOfPages,price,Publication);
}
}
public class Library1
{
public ArrayList<Publication>publicationList;
Library1()
{
publicationList=new ArrayList<>();
}
public void AddPublication(Publication firstBook)
}
{
publictionList.add(firstBook);
}
public voidshowPublications()
{
for(int i=0;i<publicationList.size();i++)
{
publication p=publicationList.get(i);
System.out.println(p.noOfPages+""+p.price+""+p.publicationName+"\n");
}
}
{
publictionList.add(firstJournal);
}
public voidshowPublications()
{
for(int i=0;i<publicationList.size();i++)
{
publication p=publicationList.get(i);
System.out.println(p.noOfPages+""+p.price+""+p.publicationName+"\n");
}
}
public static void main(String args[])
{
Publication firstBook=new Book(100,180,"O'Really");
Publication secondBook=new Book(1000,1800,"Oxford");
Publication thirdBook=new Book(2000,1880,"The Name of the Wind");
Publication firstjournal=new Book(50,500,"Windeye");
Publication secondjournal=new Book(60,600,"Battleborn");
Library1 lib=new Library1();
lib.AddPublication(firstBook);
lib.AddPublication(secondBook);
lib.AddPublication(thirdBook);
lib.AddPublication(firstJournal);
lib.AddPublication(secondJournal);
lib.showPublication();
}