• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about question 22, page 227 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Omar Talabay
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Book name: Java OCA 8 Programmer I Study Guide
on page 227, question number 22.

The answer at the end of the book is option E.
However, both code snippests start with line number 1. In addition, no imports and package names were included. Therefore, the right answer is G, the code does not compile.

Regards,
OT
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Omar Talabay,

First of all, a warm welcome to CodeRanch!

Omar Talabay wrote:The answer at the end of the book is option E.
However, both code snippests start with line number 1. In addition, no imports and package names were included. Therefore, the right answer is G, the code does not compile.

You are incorrect! The correct answer in the book is spot-on! The code will print "u u ucrcr" on execution.

Although it is a very good practice to add a package statement to your classes, it is not required. If you don't have a package statement, the class will be in the unnamed package also known as the default package. And adding import statement to a source code file is also not a requirement. You only need to add an import statement if you want to use the type by its simple name. If you for example want to use List instead of java.util.List, you need to add this import statement to your source code fileBut the code snippets in this question only contain classes from the java.lang package and this package is automatically imported by default. So you do not need to import java.lang.*; to use them without fully qualified names.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic