Java Magazine, Jan/Feb 2017
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2017 64 fix this b Sonia Mélina Jaquelina Alaïs c Sonia Mélina Alaïs d Sonia Jaquelina Alaïs e The order of output is platform dependent Question 3 Given the following code fragment line n1 Connection conn DriverManager getConnection jdbc derby localhost 1527 sample user app password app line n2 Statement statement conn createStatement line n3 ResultSet rs statement executeQuery SELECT FROM APP CUSTOMER line n4 while rs next String name rs getString NAME System out printf s n name line n5 Which releases all the database resources Choose one a Insert the following At line n1 try At line n3 At line n5 b Insert the following At line n2 try At line n4 At line n5 c Insert the following At line n3 try At line n4 At line n5 d Insert at line n5 rs close statement close Answers Question 1 The correct answers are options C and E This question probes an aspect of your understanding of inner classes The term inner class is used fairly loosely most of the time but it actually has a fairly specific meaning in the documentation An inner class is a nonstatic class declared inside another class If the class is static then its considered to be a nested class not an inner class And there are corner case rules about inner classes Section 813 of the Java Language Specification Inner Classes and Enclosing Instances states the following It is a compile time error if an inner class declares a member that is explicitly or implicitly static unless the member is a constant variable You might well ask what is a constant variable Section 4124 of the specification states that a constant variable is a final variable of primitive type or type String that is initialized with a constant expression Interestingly the compiler even rejects the value null as the constant expression for this assignment These rules mean that the code shown in the question cant work because it has an inner class attempting to declare a static variable that doesnt qualify as a constant variable As a result option A must be incorrect Also nothing in the
You must have JavaScript enabled to view digital editions.