wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is it printing mistake in  SCJP 310-065 famous Kathy sierra book? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is it printing mistake in  SCJP 310-065 famous Kathy sierra book?" Watch "Is it printing mistake in  SCJP 310-065 famous Kathy sierra book?" New topic
Author

Is it printing mistake in SCJP 310-065 famous Kathy sierra book?

Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

On page no 29, there is Toon class, where nothing is written that it is in which package or out side of any package because of there is no package statement.Now they are creating object of class Cloo, while it is impossible to access in Toon class because neither there is inheritance from Cloo class nor import statement to include it.Is it magic ?? how they are accessing it or they have advanced knowledge ?? help me to learn this book .
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11160
    
  16

if neither class has a package statement, they are both in what's called the 'default package'.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

fred rosenberger wrote:if neither class has a package statement, they are both in what's called the 'default package'.


thank you for quick response but as you said even if Toon is in default package then this code is totally wrong because Cloo is in nocert package so if we want use Cloo class for Toon then we have to write import statement in Toon class or inheritance is required, because Toon and Cloo are in different package as you said and we can see in this code.
Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115



It is impossible here to create instance of Cloo class.
Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


Bear you are great.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Try this...

This is class #1


This is class #2... you got to make a class public to invoke the main method though



but i have not gone through that page... just a guess..
Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

John Jai wrote:Try this...

This is class #1


This is class #2... you got to make a class public to invoke the main method though



but i have not gone through that page... just a guess..


no need to go there you can see code that i've posted here.i don't think you are right how you can assume that two classes is single class ,have you ever seen anywhere this logic?,even if we assume that last two classes are in one file then one of class must be public to make it executable
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Ok... lets go this way...

Have the two classes I put up like below...

cert\Roo.java - where cert is the package name

notcert\SomeClass.java - where notcert is the package name and SomeClass.java is the java FILE that holds the two classes Cloo and Toon...

now open a cmd prompt... compile Roo.java and SomeClass.java... you will have three class files... Roo.class, Cloo.class, Toon.class...

Run the Toon class by using the command -> java notcert.Toon ... did you see any output??

i don't think you are right how you can assume that two classes is single class ,have you ever seen anywhere this logic?,

I use more than a class when needed in the same java FILE...
Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

John Jai wrote:Ok... lets go this way...

Have the two classes I put up like below...

cert\Roo.java - where cert is the package name

notcert\SomeClass.java - where notcert is the package name and SomeClass.java is the java FILE that holds the two classes Cloo and Toon...

now open a cmd prompt... compile Roo.java and SomeClass.java... you will have three class files... Roo.class, Cloo.class, Toon.class...

Run the Toon class by using the command -> java notcert.Toon ... did you see any output??

i don't think you are right how you can assume that two classes is single class ,have you ever seen anywhere this logic?,

I use more than a class when needed in the same java FILE...


yes it is good trick but you haven't answer about main problem, you may have advance knowledge but my question was that what is meaning of unworkable code in book,if they cant write workable code then what they want to teach us and how ? please come to main problem how to make these nonsense classes workable and explain which is unexplained by author.sorry for bad english.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
what is meaning of unworkable code in book....

in my humble opinion any code that compiles fine is workable...

how to make these nonsense classes workable

Are you using an IDE like Eclipse rather than a text editor and cmd prompt?

I think only those who go through the page can explain you better... good luck
Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

John Jai wrote:
in my humble opinion any code that compiles fine is workable...

you are right but Toon class generates compile error that can't find Cloo symbol.
Cloo c = new Cloo();

Are you using an IDE like Eclipse rather than a text editor and cmd prompt?

I am beginner so i don't use any IDE, i am using notpad and cmd.


Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

Everyone congrats me, i had resolved this problem myself and i want to show author of SCJP 310-065 book that what changes should be there in right manner so greenhorns never get confused .








Now see it's working




John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Good... and in future please use UseOneThreadPerQuestion
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 289

Congrtas


-Chiru
Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

John Jai wrote:Good... and in future please use UseOneThreadPerQuestion


yes i'll i am a greenhorn so i didn't know about it .
Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

Chiranjeevi Kanthraj wrote:Congrtas


thank you Chiranjeevi Kanthraj for your time.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it printing mistake in SCJP 310-065 famous Kathy sierra book?
 
Similar Threads
About public access in K&B book
Public Member Access
Declaration and Access Control
Difficulty Running a Program that imports user-define package
Compila errora help me :(