Did you know, in how many ways you can declare an integer array..??
Yes/NO??
Maybe you are not aware of it..!!
1. int[] a= new int[10]; // Preffered and comon way
2. int a []= new int[10]; //Correct but not usually preferred
Does Java accepts the following things..??
int [] a [] = new int [2][2]; //Do it yourself
int a [][] = new int [2][2]; //Do it yourself
The answer is you can..!! Java compiler does not throw any error in above ways..!!
Cool isn't it??
A Java programmer knows how to declare methods, write constructors, initialize variables but the following one seems to be strange but, it is valid..!!
3. (){ /***/ }
4. ()[] { /***/ }
5. []() { /***/ }
Can we write 1 or 2 or 3 in Java program and not expecting a compiler error..??
Before you check the answer TRY it out..!!
None of them(3 or 4 or 5) gives you an error..!!
Here is the reason Let's consider an example :1
FYI: you can write a method as
someMethodName()
someReturnType -> eg: int []
Method have an opening ({) and closing ({ ) parenthesis with some statements in it.
Example 3,4,5 satisfies all the 3 conditions so for that reason you won't be getting an error..!!
All in all, (){/**/} is valid in Java and compiler does not throw any error..!!
No comments:
Post a Comment