Analyze the following code: import java.util.StringTokenizer; public class A extends StringTokenizer { }

Analyze the following code:
import java.util.StringTokenizer;
public class A extends StringTokenizer {
}


A. The program has a compilation error because A does not have a default constructor.
B. The program has a compilation error because the default constructor of A invokes the default constructor of StringTokenizer, but StringTokenizer does not have a default constructor.
C. The program would compile fine if you add the following constructor into A: A(String s) { }
D. The program would compile fine if you add the following constructor into A: A(String s) { super(s); }

The correct answer is BD


Explanation: StringTokenizer has three constructors StringTokenizer(String s), StringTokenizer(String s, String delimiters), and StringTokenizer(String s, String delimiters, Boolean returnTokens). It does not have a default constructor. If a class does not specify a constructor, a default constructor is assumed. A constructor invokes its superclass?s default constructor if it does not explicitly invoke a constructor.


Java

Learn More Multiple Choice Question :