Quiz About Java Class and Object II
Quiz About Java Class and Object II
Friend
Discuss it
Question 11 ‒ Explanation
In Java, when we implement an interface method, it must be declared
as Public. For more information on Java interface Refer:Interfaces in Ja
va option (C) is correct.
Question 12
Java
class Test {
int i;
}
class Main {
public static void main(String args[]) {
Test t = new Test();
System.out.println(t.i);
}
}
garbage value
compiler error
runtime error
Discuss it
Question 12 ‒ Explanation
In Java, fields of classes and objects that do not have an explicit initi
alizer and elements of arrays are automatically initialized with the de
fault value for their type (false for boolean, 0 for all numerical types,
null for all reference types). Local variables in Java must be definitely
assigned to before they are accessed, or it is a compile error.
1 2