Given:
What is the result?
A. Initialized
Started
B. Initialized
Started
Initialized
C. Compilation fails
D. An exception is thrown at runtime
Given:
What is the result?
A. Initialized
Started
B. Initialized
Started
Initialized
C. Compilation fails
D. An exception is thrown at runtime
C is the correct answer.
The program will not compile because method init() is private and not visible outside of class Caller. If access to init() was changed to public, choice B would be correct.
class Caller{
private void init(){
System.out.println(“Initialized”);
}
public void start(){
init();
System.out.println(“Started”);
}
}
public class TestCaller{
public static void main(String[] args){
Caller c = new Caller();
c.start();
c.init();
}
}