Java Program to Create the Outer Class BankAcct and Inner Class Interest

«
»
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.

advertisement
  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 Reference Books in Java Programming, Data Structures and Algorithms.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn