Increasing Class Encapsulation with Static Inner Class - Java Object Oriented Design

Java examples for Object Oriented Design:Inner Class

Description

Increasing Class Encapsulation with Static Inner Class

Demo Code

public class Main {
    //from ww  w. ja  v a 2 s  .c om
    static String hello = "Hello";
    
    
    public static void sayHello(){
        System.out.println(hello);
    }
    
    static class InnerExample {
        String goodBye = "Good Bye";
        
        public void sayGoodBye(){
            System.out.println(this.goodBye);
        }
    }
    
    public static void main (String[] args){
        Main.sayHello();
        Main.InnerExample inner = new Main.InnerExample();
        inner.sayGoodBye();
    }
}

Result


Related Tutorials