LoginSignup
0
0

More than 1 year has passed since last update.

anonymous class, local class, inner class

Last updated at Posted at 2023-01-04

Java Gold

interface SampleInterface {
    void method();
}
public class Outer {
    public static class InnerStatic {
        static int i1;
        static void method() {
            System.out.println("i am Inner class method of static");
        }
    }
    public class InnerInstance {
        int i1;
        void method() {
            System.out.println("i am Inner class method of instance");
        }
    }
    public static void main(String[] args) {

        class LocalClass {
            int i2;
            void method() {
            System.out.println("i am local class method");
            }
        }
        
        Outer.InnerStatic.method();

        Outer o = new Outer();
        InnerInstance ii = o.new InnerInstance();
        ii.method();
        
        LocalClass l1 = new LocalClass();
        l1.method();
        
        SampleInterface si = new SampleInterface() {
            @Override
            public void method() {
                System.out.println("i am anonymous class method");
            }
        };
        si.method();
    }
}
i am Inner class method of static
i am Inner class method of instance
i am local class method
i am anonymous class method
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0