File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes IF...ELSE Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 9033
    
  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?


Mr. C<br /> <br />Author and Instructor<br />My book:<br /><a href="http://www.aw-bc.com/catalog/academic/product/0,1144,1576761614,00.html" target="_blank" rel="nofollow">http://www.aw-bc.com/catalog/academic/product/0,1144,1576761614,00.html</a>
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: IF...ELSE
 
Similar Threads
Incorrect equals() implementation...
Prototype of the main method
Generics
hashCode() - why?
Strings