We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Practice
- Java
- Advanced
- Can You Access?
- Discussions
Can You Access?
Can You Access?
SeanRMunoz + 0 comments Two line solution that passes all TC's
o = new Inner().new Private(); System.out.println(num + " is " + ((Solution.Inner.Private)o).powerof2(num));
goyalshub + 0 comments First of all refer this document to understand the inner class creation - http://tutorials.jenkov.com/java/nested-classes.html
Now what I did is:
o = new Object(); Solution.Inner instance = new Solution.Inner(); Inner.Private inner = instance.new Private(); o = (Object) inner; System.out.println(num + " is " + inner.powerof2(num)) ;
programcoder + 0 comments Why is there security exception in this piece of code? I mean I have solved the actual problem, but I do not get the relevance of going through permission checking for exit of VM etc.
akshay_megharaj + 0 comments weird one line solution is Java
System.out.println(num + " is " + ((Solution.Inner.Private)(o = (Object) new Solution.Inner().new Private())).powerof2(num));
johnnybionic + 0 comments I solved this using reflection, as that was in the import statements, so I assumed that was what was being tested. Otherwise, it can be done in one line in Java, passes all tests (and admittedly it's much the same as SeanRMunoz's solution):
System.out.println(String.format("%d is %s", num, new Inner().new Private().powerof2(num)));
That seems too easy for a medium challenge though.
Load more conversations
Sort 75 Discussions, By:
Please Login in order to post a comment