The Wayback Machine - https://web.archive.org/web/20240213201232/https://www.geeksforgeeks.org/java-operators-question-3/
Open In App
Related Articles

Java | Operators | Question 3

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report




class Test {
    public static void main(String args[])  {
       System.out.println(10  +  20 + "GeeksQuiz"); 
       System.out.println("GeeksQuiz" + 10 + 20); 
   }  
}


(A)

30GeeksQuiz
GeeksQuiz30

(B)

1020GeeksQuiz
GeeksQuiz1020

(C)

30GeeksQuiz
GeeksQuiz1020

(D)

1020GeeksQuiz
GeeksQuiz30


Answer: (C)

Explanation: In the given expressions 10 + 20 + “GeeksQuiz” and “GeeksQuiz” + 10 + 20 , there are two + operators, so associativity comes to the picture. The + operator is left to right. So the first expression is evaluated as (10 + 20) + “GeeksQuiz” and second expression is evaluated as (“GeeksQuiz” + 10) + 20 .


Quiz of this Question

Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:

  • Comprehensive Course
  • Expert Guidance for Efficient Learning
  • Hands-on Experience with Real-world Projects
  • Proven Track Record with 100,000+ Successful Geeks

Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads