Challenge - 5 Problems
Private Access Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
Output of accessing private field within the same class
What is the output of this Java program?
Java
public class Test { private int number = 5; public void printNumber() { System.out.println(number); } public static void main(String[] args) { Test t = new Test(); t.printNumber(); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
Output when accessing private field from another class
What happens when you try to compile and run this code?
Java
public class A { private int secret = 10; } public class B { public static void main(String[] args) { A a = new A(); System.out.println(a.secret); } }
Attempts:
2 left
🔧 debug
advanced2:00remaining
Why does this code cause a compilation error?
Identify the reason for the compilation error in this code snippet.
Java
class Person { private String name; public Person(String name) { this.name = name; } } class Employee extends Person { public Employee(String name) { super(name); } public void printName() { System.out.println(name); } }
Attempts:
2 left
📝 syntax
advanced2:00remaining
Which option correctly declares a private method and calls it within the same class?
Select the code snippet that compiles and runs correctly, printing "Hello".
Attempts:
2 left
🚀 application
expert2:00remaining
How many private fields are accessible in this nested class?
Given the code below, how many private fields of Outer are accessible directly inside Inner?
Java
public class Outer { private int a = 1; private int b = 2; int c = 3; public class Inner { public int sum() { return a + b + c; } } }
Attempts:
2 left
