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.
class BankAcct
{
int principal = 200, rate = 4, time = 2;
void test()
{
Interest inner_obj = new Interest();
inner_obj.display();
}
class Interest
{
void display()
{
int si = (principal * rate * time) / 100;
System.out.println("Interest : " + si + " Rs");
}
}
}
public class InnerClassDemo
{
public static void main(String args[])
{
BankAcct outer_obj = new BankAcct();
outer_obj.test();
}
}
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.
Related Posts:
- Apply for Java Internship
- Practice Programming MCQs
- Check Programming Books
- Check Java Books
- Practice BCA MCQs