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
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Java
  3. Advanced
  4. Can You Access?
  5. Discussions

Can You Access?

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 75 Discussions, By:

votes

Please Login in order to post a comment

  • SeanRMunoz 4 years ago+ 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));
    
    48|
    Permalink
  • goyalshub 5 years ago+ 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)) ;
    
    22|
    Permalink
  • programcoder 5 years ago+ 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.

    9|
    Permalink
  • akshay_megharaj 4 years ago+ 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));
    
    3|
    Permalink
  • johnnybionic 4 years ago+ 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.

    3|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature