Java Online Compiler
Example: Simple Interest Program in Java using Inheritance
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Simple Interest Program in Java using Inheritance import java.util.Scanner; // This class will calculate the simple interest class CalcSimpleInterest { public float CalculateInterest(float x, float y, float z) { return (x * y * z) / 100; } } // This class will inherit `CalcSimpleInterest` class and print the simple interest class PrintSimpleInterest extends CalcSimpleInterest { public void PrintInterest(float SI) { System.out.println("\nSimple Interest = " + SI); } } public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter the principal (amount), time, and rate::"); float p = in.nextFloat(); // value of the principal float t = in.nextFloat(); // value of the time float r = in.nextFloat(); // value of the rate PrintSimpleInterest SimpleInterest = new PrintSimpleInterest(); // It will calculate the simple interest float SI = SimpleInterest.CalculateInterest(p, t, r); // It will produce the final output SimpleInterest.PrintInterest(SI); } }
54 67 90
Output
Clear
ADVERTISEMENTS