Static method in Thread class
static native void yield()
static void sleep(long millis, int nanos) throws InterruptedException
But the real fact is that you cannot override the static methods.
Well, this is very important that the methods have been defined in Thread class and it is always overridden to create different threads.
If we allow the sleep and yield methods to be overridden then we will lose the complete functionality or use of the methods. This is why these methods have been made static.

     Type
Description
A class created within class and outside method.
A class created for implementing interface or extending class.
Its name is decided by the java compiler.
A class created within method.
A static class created within class.
An interface created within class or interface.

public class InnerClass {
     class A {
           public void showA() {
                System.out.println("I am in showA");
           }
     }

     static class B {
           public void showB() {
                System.out.println("I am in showB");
           }
     }

     public static void main(String[] args) {
           InnerClass.B nestedObject =new InnerClass.B();
           nestedObject.showB();
          
           InnerClass.A inner = new InnerClass().new A();
           inner.showA();
     }

}

Comments

Popular posts from this blog