DEVFYI - Developer Resource - FYI

Can you declare a class as private?

Java Interview Questions and Answers (part 1)


(Continued from previous question...)

137. Can you declare a class as private?

Yes, we can declare a private 
class as an inner class. For example,

class MyPrivate {
    private static class MyKey {
        String key = "12345";
    }
    public static void main(String[] args) {
System.out.println(new MyKey().key);//prints 12345
    }
}

(Continued on next question...)

Other Interview Questions