+ 5

What will be the output of the following code ??

class Arrays{ public static void main(String args[]){ int a[]={23,34,56,67,99}; int b[]=a; int sum=sumOfArray(b); System.out.println(sum); } static int sumOfArray(int a[]){ int sum=0; for(int i:a){ sum+=i; } return sum; } }

24th Dec 2016, 5:55 PM
Jenny Lance
Jenny Lance - avatar
5 odpowiedzi
+ 4
Nothing... because you can't inherit from String wich is a final class ^^
24th Dec 2016, 5:51 PM
visph
visph - avatar
+ 4
The output would be the sum of all the elements in array 'a' (since b got it from a), which is 279. I don't quite see anything related to inheriting from String here.
24th Dec 2016, 5:59 PM
Wen Qin
Wen Qin - avatar
+ 4
@K2 Shape: The initial post has been edited... Previously the code starting with: class Arrays extends String {
24th Dec 2016, 6:02 PM
visph
visph - avatar
+ 2
o ok, that was my bad, if it was `class Arrays extends String` then yes, it would output nothing
24th Dec 2016, 6:05 PM
Wen Qin
Wen Qin - avatar
0
addition of all array of numbers
11th Jan 2017, 6:36 PM
Kallanagouda Biradar