aspose file tools*
The moose likes Beginning Java and the fly likes IF...ELSE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "IF...ELSE" Watch "IF...ELSE" New topic
Author

IF...ELSE

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192

C:\Java\EigeneJavaProgramme>java ZombieStomp
Killer Of Giants
Symphony of Destruction
If str = „markl“ then (str instanceof String) is true
AND (str instanceof Object) is true.
Why doesn’t it print:
Killer Of Giants
I Shot the Sheriff
Symphony of Destruction
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10


If str = „markl“ then (str instanceof String) is true
AND (str instanceof Object) is true.
Why doesn’t it print:


Killer Of Giants
I Shot the Sheriff
Symphony of Destruction


because of the 'else'. Read --

if str is an instance of string => print Killer Of Giants

or else if string is not an instance of string but is an instance of Object => print I Shot the Sheriff

then always print Symphony of Destruction


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
Is there any particular reason you added the final keyword in the main method header?


Author and Instructor, my book
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
If your first condition evaluate to true, the "else" won't be evaluated.


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IF...ELSE