Java Runtime Polymorphism Example: Bank

Consider a scenario where Bank is a class that provides a method to get the rate of interest. However, the rate of interest may differ according to banks. For example, SBI, ICICI, and AXIS banks are providing 8.4%, 7.3%, and 9.7% rate of interest.

Figure 4.15: Polymorphism example - bank
Image bankinheritance


\begin{lstlisting}
class Bank{
float getRateOfInterest(){return 0;}
}
class ...
...tln(''AXIS Rate of Interest: ''+b.getRateOfInterest());
}
}
\end{lstlisting}

Output:


\begin{lstlisting}
SBI Rate of Interest: 8.4
ICICI Rate of Interest: 7.3
AXIS Rate of Interest: 9.7
\end{lstlisting}