wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes extends 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 "extends" Watch "extends" New topic
Author

extends

Ale Lima
Greenhorn

Joined: Jan 04, 2009
Posts: 15
People help me ...

In this code why I get the result Sub1 2 and not 1 Sub 2?



Preparing for my SCJP 6 exam
Rafael Angarita
Ranch Hand

Joined: Jan 09, 2009
Posts: 67
Check this:

http://www.coderanch.com/t/427166/Programmer-Certification-SCJP/certification/from-Exam-lab-practice-Exam#1895372


Rafael Angarita.
SCJP 6.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Ale when you post a question, then you must also tell from where did you copy the question. Here now we know that it is from Examlab, but for future keep in mind to disclose the name of the mock exam from where you post a question


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ben Zaidi
Ranch Hand

Joined: Apr 08, 2007
Posts: 151
Well, i saw the first post. I am wondering why

System.out.print(ga.i + " " + ga.getI())

will first evaluate the getI() method. I am confused, can anyone clarify this doubt please?

Thanks


Ben,
--Lost in preparation of SCJP and SCWCD--
"Start writing a new chapter, for if you live by the book you'll never make history." (Ben Sobel)
Ale Lima
Greenhorn

Joined: Jan 04, 2009
Posts: 15
Hi Ben.

I understood that a static method is a method you can call without having to first create an object from a class.
So, the line 8 will execute first, because print is a static method.

[]'
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Ben Zaidi wrote:Well, i saw the first post. I am wondering why

System.out.print(ga.i + " " + ga.getI())

will first evaluate the getI() method. I am confused, can anyone clarify this doubt please?

Thanks




is evaluated this way:



so to append ga.getI(); first ga.getI() is evaluated completely that prints "Sub", and after that whatever returned by ga.getI() is appended to ga.i value and space value, then converted to String from StringBuilder than printed.


SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extends