Learn Java: Declarations And Access Control

Topics: All about Declarations And Access Control'

Browse all answers:

Explain Private in java?
Explain protected in java?
Explain public in java?
Explain default in java?
Explain final in java?
Explain abstract in java?
Explain transient in java?
Explain volatile in java?
Explain Arrays in java?
Explain Declaration of Arrays without allocation?
Example of Arrays?
How arrays know their own size?
Explain Java vs Visual Basic Arrays?
Explain Combined declaration and initialization of Arrays?
How can you re-size an array in a single statement whilst keeping the original contents?1) Use the setSize method of the Array class2) Use Util.setSize(int iNewSize)3) use the size() operator4) None of the above
You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it?public class MyAr{public static void main(String argv[]){        int[] i = new int[5];        System.out.println(i[5]);        }}1) Compilation and output of 02) Compilation and output of null3) Compilation and runtime Exception4) Compile time error
You want to loop through an array and stop when you come to the last element. Being a good Java programmer, and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use?1)myarray.length();2)myarray.length;3)myarray.size4)myarray.size();
Your boss is so pleased that you have written HelloWorld he she has given you a raise. She now puts you on an assignment to create a game of TicTacToe (or noughts and crosses as it was when I were a wee boy). You decide you need a multi dimensioned array to do this. Which of the following will do the job?1) int i      =new int[3][3];2) int[] i    =new int[3][3];3) int[][] i  =new int[3][3];4) int i[3][3]=new int[][];
You want to find a more elegant way to populate your array than looping through with a for statement. Which of the following will do this?   1)    myArray{       [1]="One";       [2]="Two";       [3]="Three";    end with   2)String s[5]=new String[] {"Zero","One","Two","Three","Four"};3)String s[]=new String[] {"Zero","One","Two","Three","Four"};4)String s[]=new String[]={"Zero","One","Two","Three","Four"}; 
What will happen when you attempt to compile and run the following 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);    }}1) Compile time error, ia3 is not created correctly2) Compile time error, arrays do not have a length field3) Compilation but no output4) Compilation and output of 3
Which of these array declarations and instantiations are not legal?Select all valid Answers:(a) int []a[] = new int[4][4];(b) int a[][] = new int[4][4];(c) int a[][] = new int[][4];(d) int []a[] = new int[4][];(e) int[][] a = new int[4][4];(f) int [ ] [ ] a = new int[4][4];
Which of these array declarations and initialization are not legal?Select all valid Answers:(a) int []i[] = {{1,2}, {1}, {}, {1,2,3}};(b) int i[]= new int[2]{1, 2};(c) int i[][] = new int[][]{{1,2,3}, {4,5,6}};(d) int i[][] = {{1, 2}, new int[2]};(e) int i[4] = {1, 2, 3, 4};
Which of these statements are true?Select all valid Answers:(a) All classes must define a constructor.(b) A constructor can be declared private.(c) A constructor can declare a return value.(d) A constructor must initialize all the member variables of a class.(e) A constructor can access the non-static members of a class
Which of these statements are true?Select all valid Answers:(a) Transient variables will not be saved during serialization.(b) Constructors can be declared abstract.(c) The initial state of an array object constructed with the statement int a[] = new int[10] will depend on whether the variable a[] is a local variable, or a member variable of a class.(d) Any subclass of a class with an abstract method must implement a method body for that method.(e) Only static methods can access static members.
Which of the following are Java modifiers?(a) public(b) private(c) friendly(d) transient(e) vagrant
Which of the following method will not give you any error when placed on line no.3?Select one correct answer.1 interface i22 {3 //Here4 }(a) static void abc();(b) abstract void abc();(c) native void abc();(d) synchronized void abc();(e) final void abc();(f) private void abc();(g) protected void abc();