JAVA
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
//by Atila
//learned this concept from hackerrank.com
//https://www.hackerrank.com/challenges/30-generics/tutorial
//https://youtu.be/Z9uAwnz_wBA
import java.util.*;
class Car implements Comparable <Car>{
private int price;
private String name;
public Car (String name, int price) {
this.price = price;
this.name = name;
}
@Override
public int compareTo (Car x) {
if (this.price > x.price)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run