Given:
What is the result?
A.
An exception is thrown at runtime.
B.
Initialized
Started
Initialized
C.
Initialized
Started
D.
Compilation fails.
Given:
What is the result?
A.
An exception is thrown at runtime.
B.
Initialized
Started
Initialized
C.
Initialized
Started
D.
Compilation fails.
correct answer is A
D
You cannot call private methods from outside the class they were declared.
Answer: D
package q039;
public class Caller {
private void init() {
System.out.println(“Initialized”);
}
private void start() {
init();
System.out.println(“Started”);
}
}
package q039;
public class TestCall {
public static void main(String[] args) {
Caller c = new Caller();
c.start(); //start is private
c.init(); //init() is also private
}
}
Output:
Exception in thread “main” java.lang.Error: Unresolved compilation problems:
The method start() from the type Caller is not visible
The method init() from the type Caller is not visible
output cannot be resolved or is not a field
at q039.TestCall.main(TestCall.java:7)
D