Java Methods 1: Passing a reference to an array

preview_player
Показать описание
Being able to trace how programs work by drawing memory models is super important!

Here we focus on passing a method a reference to an int array and then modifying a value within that array.

public class JavaPractice {
public static void main(String[] args){
int x = 29;
int[] nums = new int [3];
nums[1] = 25;
method1(nums);
}
public static void method1(int[] input){
input[2] = 21;
}
}

Check out the previous video about passing an int to a method

Рекомендации по теме
Комментарии
Автор

Wow, this is awesome technique of teaching

simmijassal
Автор

a great way of teaching. Thanks
what happens if I try to pass a reference to array.
say I have a swap function it's signature looks like this static void swap(ref in [ ] x, ref int [ ] y);
and then it swap. can you explain this case like the way in video

ahmedkareem
welcome to shbcf.ru