Java Program to Create Outer Class Bank Account and the Inner Class Interest in it

This is a Java Program to Create the Outer Class BankAcct and Inner Class Interest.

We declare the Outer class as BankAcct and inner class as Interest. Now we use the varaibles declared in the outer class to get the output in the inner class.

Here is the source code of the Java Program to Create the Outer Class BankAcct and Inner Class Interest. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. class BankAcct 
  2. {
  3.     int principal = 200, rate = 4, time = 2;
  4.     void test() 
  5.     {
  6.         Interest inner_obj = new Interest();
  7.         inner_obj.display();
  8.     }
  9.     class Interest 
  10.     {
  11.         void display() 
  12.         {
  13.             int si = (principal * rate * time) / 100;
  14.             System.out.println("Interest : " + si + " Rs");
  15.         }
  16.     }
  17. }
  18. public class InnerClassDemo 
  19. {
  20.     public static void main(String args[]) 
  21.     {
  22.         BankAcct outer_obj = new BankAcct();
  23.         outer_obj.test();
  24.     }
  25. }

Output:

$ javac InnerClassDemo.java
$ java InnerClassDemo
 
Interest : 16 Rs

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.