Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Programmer Certification (OCPJP)
sequence confusion
gaurav gupta sitm
Greenhorn
Posts: 22
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class C { public static void main(String arg[]) { System.out.println("A"+new C()); } public String toString() { System.out.print("B"); return "C"; } }
Output : BAC
why output is BAC instead of ABC ???/
Javin Paul
Ranch Hand
Posts: 300
I like...
posted 14 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
because before this line completes , its created a "C" object and then its toString() method is get called
System.out.println("A"+new C());
which prints "B" and return "C" , which makes output of below line as "AC"
System.out.println("A"+new C())
so essentially you have two System.out.println statement , which print "B" +"AC"
Thanks
JAvin
OJAJP 8 FAQ
Free Java 8 Mock Exams
Java 8 Certification Guide
OCAJP Books
OCAPJP and OCPJP guide
Curse your sudden but inevitable betrayal! And this tiny ad too!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Proper initialization warning
String combinations & permutations
String question
why the ouput is like this ?
Different output without the parantheses
More...