Wednesday 6 May 2015

Top level class modifiers in Java

-- Top level classes can only have

1.  publilc

2.  default/package

3.  abstarct

4.  final

5.  strictfp

If we are using any other modifier we will get compile time error. 

Example:

private class Test
{
public static void main(String args[]){
int i=0;
System.out.println("Test"+i);
}
}

>javac Test.java
Test.java:1: modifier private not allowed here
private class Test

but For the inner classes the following modifiers  are aslo allowed.
 private, protected, and static.

If you know anyone who has started learning Java, why not help them out! Just share this post with them. Thanks for studying today!...

1 comment: