PYQPulse
HomeMocksPracticePYQsUpdatesDashboard
PYQPulse

Timing-accurate mock tests and PYQs for SSC, Banking and Railway exams — so the real paper feels like a revision.

Exams

  • SSC exams
  • Banking exams
  • Railway exams
  • All exams

Practice

  • Practice questions
  • Mock test series
  • Sectional tests
  • Year-wise PYQs
  • Performance analytics

Company

  • About us
  • Help Centre
  • Pricing
  • Sign in

Legal

  • Privacy Policy
  • Terms of Service

Contact

  • hello@testwala.co.in
  • Telegram
  • +91 62816 87760

Practice interface modeled on the official exam pattern — not the official examination. PYQPulse is not affiliated with the Staff Selection Commission, IBPS, SBI, RBI, NABARD, SEBI or Indian Railways.

© 2026 PYQPulse. All rights reserved.

Built for aspirants, by aspirants.

HomeMocksPracticeStats
  1. Home
  2. ›
  3. PYQs
  4. ›
  5. RRB Junior Engineer / DMS / CMA
  6. ›
  7. 2019
  8. ›
  9. Q3633

RRB Junior Engineer / DMS / CMA 2019 · Question 3633 of 3719

What will be the output of the following Java program? public class SumOfArray { public static void main(String[ ] args) { int [ ] arr = new int [ ] {1, 2, 3, 4}; int sum = 0; for (int i = 0; i < arr.length; i++) { sum = sum + arr[i]; } System.out.println("Sum of all the elements of an arry: " + sum); } }

  1. ASum of all the elements of an array: 9
  2. BSum of all the elements of an array: 10Correct
  3. Csum of all the elements of an array: 12
  4. DError

Answer: B. Sum of all the elements of an array: 10

Explanation

The correct answer is option 2. Concept: An array in Java is an object that contains elements of the same data type. Furthermore, the items of an array are kept in a single memory address. It's a data structure where we save items that are comparable. In a Java array, we can only hold a fixed number of items. The given Java code is, public class SumOfArray { public static void main(String[ ] args) int [ ] arr = new int [ ] {1, 2, 3, 4}; int sum = 0; for (int i = 0; i < arr.length; i++) { sum = sum + arr[i]; } System.out.printIn("Sum of all the elements of an arry: " + sum); } } Explanation: "arr" is an integer array it has four elements like, arr[0]=1; arr[1]=2; arr[2]=3; arr[3]=4; And initially, the sum has zero, and each iteration of the for-loop adds to the sum. At end of the sum, the variable has added all elements in an integer arr of four elements. sum=1+2+3+4; And sum=10 Prints like Sum of all the elements of an array: 10 as output. Hence the correct answer is the S um of all the elements of an array: 10.

Source: RRB JE 2019 (CBT 2) (IT) Previous Year Paper (30 Aug 2019) — prepp.in solved-paper PDF (answer key with explanations) · reliable-secondary

← Q3632View full paper (3719 questions)Q3634 →

Practice the full RRB Junior Engineer / DMS / CMA 2019 paper

Timed test with all 3719 questions, just like the real exam.

Start test