-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainchoco.java
More file actions
47 lines (41 loc) · 896 Bytes
/
mainchoco.java
File metadata and controls
47 lines (41 loc) · 896 Bytes
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
/*wap to create class "Chocolate" having data
members 'ChocoName' and 'ChocoQuantity'.
Derive a class 'ChocoFlavor' having data
member 'FlavorName'. Initilize the values for
two objects of 'ChocoFlavor' class using
constructor and display it.
*/
class Chocolate
{
String chocoName;
int chocoQuantity;
Chocolate(String s, int n)
{
chocoName = s;
chocoQuantity = n;
}
}
class ChocoFlavor extends Chocolate
{
private String flavorName;
ChocoFlavor(String s, int n, String f)
{
super(s,n);
flavorName = f;
}
public void show()
{
System.out.println("Chocolate name is:"+chocoName);
System.out.println("Number of chocolates are:"+chocoQuantity);
System.out.println("Flavor name is:"+flavorName);
}
}
class MainChoco
{
public static void main(String args[])
{
ChocoFlavor cf1=new ChocoFlavor("dairymilk", 10, "choco");
ChocoFlavor cf2=new ChocoFlavor("milkibar", 5, "milky");
cf1.show();
}
}