In the course of the interviews I identified for myself several interesting tasks on the basic knowledge of the Java language. Here are two good ones:
I. What happens during class performance?
public class Finally {
public static void main (String [] args) {
try {
return;
} finally {
System.out.println ("finally");
}
}
}
A. The compiler will generate an error.
B. Prints the "finally".
C. Nothing prints.
Ii. Will the output change if in class A the doInternal () method replaces the access modifier: 1) with private, 2) with public?
public class A {
public static void main (String [] trs) {
new B (). doPublic ();
}
public void doPublic () {
doInternal ();
}
protected void doInternal () {
System.out.println ("Do internal in A");
}
}
class B extends A {
public void doInternal () {
System.out.println ("Do internal in B");
}
}