Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extends

 
Ale Lima
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People help me ...

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

 
Rafael Angarita
Ranch Hand
Posts: 67
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ben Zaidi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ale Lima
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic