• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what if both classes where not in the same package? because in the question there's no where they mention that they're in the same package
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

desire aheza wrote:what if both classes where not in the same package? because in the question there's no where they mention that they're in the same package


If they weren't in the same package, there would be a package statement. Since there is not, they are both in the default package.
 
desire aheza
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jeanne, that answers my question. I appreciate your help!
 
I don't even know how to spell CIA. But this tiny ad does:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic