Given:
class Caller {
private void init () {
System.out.println("Initialized");
}
private void start () {
init(];
System.out.println("Started") ;
}
public class TestCall {
public static void main(String[] args) { Caller c – new Caller(); c.start (); c.init();
}
}
What is the result?
A. An exception is thrown at runtime.
B. Initialized Started Initialized
C. Initialized Started
D. Compilation fails.
Option D compilations fails due to private method calling
Answer D:
We have here two classes. The caller class is calling private methods. Therefore, compilation fails.
you are wrong, compilation fails because the access modifier private
D
Actually compilation fails due to private methods calls, c.start() and c.init()
Because the main method is static but TestCall class is not. Actually, every static method must be in a static class.