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
advertisement

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

If you find any mistake above, kindly email to [email protected]

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
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.