I'm new to java. I'm learning Interfaces and I'm trying to do the following:
package comparator;
import java.io.*;
import java.util.*;
public class comparator {
public static bankAccount ba=new bankAccount(80);
public static void main(String args[]){
method1(ba);
}
public static void method1(bankAccount ba1){
bankAccount ba2=new bankAccount(80);
int c=((Comparable) ba1).compareTo(ba2);
System.out.println(c);
}
}
class bankAccount{
public double balance;
public A(double bal){
balance=bal;
}
}
But I'm getting an error as below:
Exception in thread "main" java.lang.ClassCastException: comparator.bankAccount cannot be cast to java.lang.Comparable
at comparator.comparator.method1(comparator.java:25)
at comparator.comparator.main(comparator.java:20)
I'm unable to understand this new type of error. Any help would be really appreciated.