-
Notifications
You must be signed in to change notification settings - Fork 3
/
InheritanceDemo.java
49 lines (49 loc) · 1.07 KB
/
InheritanceDemo.java
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
class Book
{
String author;
String title;
String publisher;
Book(String a,String t,String p)
{
author=a;
title=t;
publisher=p;
}
void put()
{
System.out.println("Author Name:- "+author);
System.out.println("Title of the book:- "+title);
System.out.println("Published by:- "+publisher);
}
}
class BookInfo extends Book
{
float price;
int stock_position;
BookInfo(float pr,int sp,String a,String t,String p)
{
super(a,t,p);
price=pr;
stock_position=sp;
}
void output()
{
put();
System.out.println("Price:- "+price);
System.out.println("Stock position:- "+stock_position);
}
}
class InheritanceDemo
{
public static void main(String args[])
{
BookInfo b1=new BookInfo(7500.0f,300,"Yashwant Kanetkar","Let Us C","XYZ");
b1.output();
System.out.println( );
BookInfo b2=new BookInfo(6500.0f,550,"Dennis Ritchie","The C programming language","ABC");
b2.output();
System.out.println( );
BookInfo b3=new BookInfo(8000.0f,100,"Herbert Schildt","The complete reference of C","PQR");
b3.output();
}
}