Declaration and access control in JAVA Online Test

How to resize an array in a single statement while keeping the original contents?


To find out the last element of an array, the code written is:

public class MyAr{

public static void main(String argv[]){

int[] i = new int[5];

System.out.println(i[5]);

}

}

What happens when compiled?


If you want to traverse through the elements of an array and stop when you reach the last element, knowing that arrays contain information about their size, which one of the following are you going to use?


If an array is defined as static char a[10]; then the elements of a will be set to
an undetermined value
zero
blank character
character ‘~0’

To create a game of TIC-TAC-TOE, you need to declare a multi - D array.

Which of the given belowoption will do the work for you?


Which is a better way to populate your array without using a FOR statement?


What will happen when you compile and execute the following piece of code?

public class Ardec{

public static void main(String argv[]){

Ardec ad = new Ardec();

ad.amethod();

}

public void amethod(){

int ia1[]= {1,2,3};

int[] ia2 = {1,2,3};

int ia3[] = new int[] {1,2,3};

System.out.print(ia3.length);

}

}






























Description:

Questions span array declarations in JAVA.

Discussion

Suriya Akter

Good questions!!

1316 days 6 hours 47 minutes ago

Biswadip Goswami
Knowledge is Power !
User
2 Members Recommend
56 Followers

Your Facebook Friends on WizIQ