14. | Which two of the following are legal declarations for nonnested classes and interfaces?
| |||||||
Answer: Option C Explanation: (3), (6). Both are legal class declarations. (1) is wrong because a class cannot be abstract and final—there would be no way to use such a class. (2) is wrong because interfaces and classes cannot be marked as static. (4) and (5) are wrong because classes and interfaces cannot be marked as protected. |
Kapil said: (Dec 30, 2010) | |
Class(NonNested) can be public,default,final or abstract. But class can't marked as both fianl and abstract |
Amit said: (Feb 12, 2014) | |
If interface is marked as static then there would be no meaning of using interface. It is meant to be implemented by many classes or interfaces. If we use "static" then there will be only one copy of it which we don't want in anyway! |
Ivan said: (Aug 19, 2014) | |
Final can not be used with the combination interface, its gives an error saying "illegal combination of modifiers". |
Rishi Pathak said: (Nov 26, 2014) | |
This wrong! Interface can't be final. Suppose I Say Final Interface :-). Then we will not be able to Provide body to the method declared in Interface. This will lead to uselessness of interface. So Java Compiler will say WTF! This Is An "illegal combination of modifiers". |
Aayush said: (Jun 22, 2015) | |
Please clear about (4) option. How class can't be protected? |
Agata said: (Jan 28, 2018) | |
public static interface Test {} This code will compile. Answer number (2) should be valid, although I have no idea how to use such construction. |
Post your comments here:
Name *:
Email : (optional)
» Your comments will be displayed only after manual approval.
6. | What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package? | |||||||||
Answer: Option E Explanation: default access is the "package oriented" access modifier. Option A and C are wrong because public and protected are less restrictive. Option B and D are wrong because abstract and synchronized are not access modifiers. |
7. | Which of the following is/are legal method declarations?
| |||||||
Answer: Option D Explanation: All the given statements are legal declarations. |
8. | Which cause a compiler error? | |||||||||
Answer: Option B Explanation: Option B generates a compiler error: <identifier> expected. The compiler thinks you are trying to create two arrays because there are two array initialisers to the right of the equals, whereas your intention was to create one 3 x 3 two-dimensional array. To correct the problem and make option B compile you need to add an extra pair of curly brackets: int [ ] [ ] scores = { {2,7,6}, {9,3,45} }; |