-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerics.java
More file actions
31 lines (29 loc) · 882 Bytes
/
generics.java
File metadata and controls
31 lines (29 loc) · 882 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
public class generics {
public static void main(String[]args)
{
//generics= concept in which u write classes ,interfaces ,methods with compatible data types
//<t> type parameter(placeholder replaced by real value)
//<String> type argument(specifies the type)
Product<String,Integer,Integer> prod=new Product<>("pen",10,20);
System.out.println("item- "+prod.getitem());
System.out.println("price- "+prod.getprice());
System.out.println("quantity- "+prod.getquantity());
}
}
class Product<T,U,V>{
T item;
U price;
V quantity;
Product(T item,U price,V quantity)
{
this.item=item;
this.price=price;
this.quantity=quantity;
}
T getitem(){
return this.item;}
U getprice(){
return this.price;}
V getquantity(){
return this.quantity;}
}