- Home
- Programming
- OCA Java SE8
1.
Which of the following method signatures is a valid declaration of an entry point in a
Java application?
- A.public void main(String[] args)
- B.public static void main()
- C.private static void start(String[] mydata)
- D.public static final void main(String[] mydata)
- Answer & Explanation
- Report
Answer : [D]
Explanation :
Explanation :
An entry point in a Java application consists of a main() method with a single String[] argument, return type of void, and modifiers public and static. The name of the variable in the input argument does not matter. Option A is missing the static modifier, Option B is missing the String[] argument, and Option C has the wrong access modifier and method name. Only Option D fulfills these requirements. Note that the modifier final is optional and may be added to an entry point method. |
2.
The following class diagram demonstrates the relationship between Gold and Silver,
which extend the Metal class. Assume the attributes are all declared public. Which
statement about the diagram is not true?
- A.The diagram demonstrates platform independence in Java.
- B.The diagram demonstrates object-oriented design in Java.
- C.The Gold and Silver classes inherit weight and color attributes from the Metal class.
- D.Gold does not inherit the luster attribute.
- Answer & Explanation
- Report
Answer : [A]
Explanation :
Explanation :
The diagram is an example of object-oriented design in Java, making Option B a true statement. Options C and D are also true, as they follow from the inheritance model in the diagram. Option A is the correct answer, since platform independence has nothing to do with the diagram. |
3.
What is the proper filename extension for a Java bytecode compiled file?
- A..java
- B..bytecode
- C..class
- D..dll
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The proper extension for a Java compiled bytecode file is .class, making Option C the correct answer. |
4.
Given that a Date class exists in both the java.util and java.sql packages, what is the
result of compiling the following class?
1: import java.util.*; 2: import java.sql.*; 3: public class BirthdayManager { 4: private Date rob = new Date(); 5: private java.util.Date sharon = new java.util.Date(); 6: }
1: import java.util.*; 2: import java.sql.*; 3: public class BirthdayManager { 4: private Date rob = new Date(); 5: private java.util.Date sharon = new java.util.Date(); 6: }
- A.The code does not compile because of lines 1 and 2.
- B.The code does not compile because of line 4.
- C.The code does not compile because of line 5.
- D.The code compiles without issue.
- Answer & Explanation
- Report
Answer : [B]
Explanation :
Explanation :
Because the variable name isn’t assigned a value, the following line of The fact that the Date class exists in both packages does not impact the ability to import both packages, so lines 1 and 2 compile without issue, and Option A is incorrect. Line 4 will not compile because the Date class used is ambiguous, making Option B correct and Option D incorrect. Finally, Option C is incorrect because line 5 does compile, as the fully qualified name of the class is used. |
5.
Which of the following is not a facet of traditional object-oriented programming
languages?
- A.Objects are grouped as procedures, separate from the data they act on.
- B.An object can take many forms via casting.
- C.An object can hold data, referred to as attributes.
- D.An object can perform actions, via methods.
- Answer & Explanation
- Report
Answer : [A]
Explanation :
Explanation :
Options B, C, and D are each attributes of traditional object-oriented programming. Option A is incorrect as an object-oriented project tends to group data and the actions related to that data into a single object. |