Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 132

Which two class definitions fail to compile? (Choose two.)

A.

B.

C.

D.

E.

    Correct Answer:

    To determine which two class definitions fail to compile, we need to examine each given class definition carefully. Starting with class A3, this is an abstract class with a private static integer and a public method, both of which are acceptable Java syntax. Next, class A1 is a final class with a public constructor, which is also acceptable. For class A2, the issue is that it is declared with the private modifier, which is illegal for top-level class declarations in Java. Moving on to class A4, there is nothing wrong since it has a protected static final integer and a private constructor, both of which are legal. Lastly, class A5 is declared as both final and abstract, which is not allowed in Java because a class cannot be both final and abstract. Therefore, the two class definitions that fail to compile are A2 and A5.

Discussion
carloswork

Answer is CE. To test: /* A */ abstract class A3 { private static int i; public void doStuff(){} public A3(){} } /* B */ final class A1 { public A1(){} } /* C */ private class A2{ // Illegal Modifier for the class A2 private static int i; private A2(){} } /* D */ class A4 { protected static final int i = 10; private A4() {} } /* E */ final abstract class A5 { // The class A5 can be either final or abstract, not both protected static int i; void doStuff() {} abstract void doIt(); }

iSnover

The correct answer is CE: C -> You cannot put the keyword "private" in a class, either it is public or has the default access which can be put or not. E -> You cannot have an abstract and final class at the same time.

7df49fb

Class C: The class A2 is declared with the illegal modifier private, which is not permitted for a top-level class declaration. Class E: The class A5 is declared as both final and abstract, which is not allowed. A class can be either final or abstract, not both.

dsms

correct answer is: C E

Rajeevkuamr

Sorry,C & E

Rajeevkuamr

D&E are the answers.

shivkumarx

Answer is: C & E You can't have a final abstract class, D is legal