Computing Magazine

Java Declaration and Access Control- Quiz 0.1

Posted on the 17 April 2012 by In7rud3r
<a href="http://www.yesadvertising.com">affiliate marketing</a>Given the following declaration, which expression returns the size of the array, assuming the array has been initialized?
int[] array;
Select the one correct answer.
Your Ad Here
array[].length()
array.length()
array[].length
array.length
array[].size()
array.size()
Is it possible to create arrays of length zero? Select the one correct answer.
Your Ad Here
Yes, you can create arrays of any type with length zero.
Yes, but only for primitive data types.
Yes, but only for arrays of object references.
No, you cannot create zero-length arrays, but the main() method may be passed a zero-length array of String references when no program arguments are specified.
No, it is not possible to create arrays of length zero in Java.
Which one of the following array declaration statements is not legal? Select the one correct answer.
Your Ad Here
int []a[] = new int [4][4];
int a[][] = new int [4][4];
int a[][] = new int [][4];
int []a[] = new int [4][];
int [][]a = new int [4][4];
What would be the result of attempting to compile and run the following program?
// Filename: MyClass.java
class MyClass {
public static void main(String[] args) {
int size = 20;
int[] arr = new int[ size ];
for (int i = 0; i < size; ++i) {
System.out.println(arr[i]);
}
}
}
Select the one correct answer.
Your Ad Here
The code will fail to compile because the array typei nt[] is incorrect.
The program will compile, but will throw an ArrayIndexOutOfBoundsException when run.
The program will compile and run without error, but will produce no output.
The program will compile and run without error and will print the numbers 0 through 19.
The program will compile and run without error and will print 0 twenty times.
The program will compile and run without error and will prinnt ull twenty times.
Given the following program, which statement is true?
class MyClass {
public static void main(String[] args) {
String[] numbers = { "one", "two", "three", "four" };
if (args.length == 0) {
System.out.println("no arguments");
} else {
System.out.println(numbers[ args.length ] + " arguments");
}
}
}
Select the one correct answer.
Your Ad Here
The program will fail to compile.
The program will throw a NullPointerException when run with zero program arguments.
The program will print "no arguments" and "two arguments" when called with zero and three program arguments, respectively.
The program will print "no arguments" and "three arguments" when called with zero and three program arguments, respectively.
The program will print "no arguments" and "four arguments" when called with zero and three program arguments, respectively.
The program will print "one arguments" and "four arguments" when called with zero and three program arguments, respectively.
What would be the result of trying to compile and run the following program?
public class DefaultValuesTest {
int[] ia = new int[1];
boolean b;
int i;
Object o;
public static void main(String[] args) {
DefaultValuesTest instance = new DefaultValuesTest();
instance.print();
}
public void print() {
System.out.println(ia[0] + " " + b + " " + i + " " + o);
}
}
Select the one correct answer.
Your Ad Here
The program will fail to compile because of uninitialized variables.
The program will throw a java.lang.NullPointerException when run.
The program will print "0 false NaN null".
The program will print "0 false 0 null" .
The program will print "null 0 0 null".
The program will print "null false 0 null"
" />
<a href="http://www.yesadvertising.com">affiliate marketing</a>

You Might Also Like :

Back to Featured Articles on Logo Paperblog

These articles might interest you :

  • Rewind: It’s the 90s

    Rewind: It’s

    It seems that the 1990s are everywhere right now. What’s old is new again and all that. The last concert of the summer, I took it to another level when I... Read more

    The 25 September 2018 by   Irene Gomes
    FASHION, LIFESTYLE
  • Thomas Land | Drayton Manor Park

    Thomas Land Drayton Manor Park

    If living near a theme park was in your criteria for buying a house, then our new house would certainly meet that need. Living about a 3 minute drive from... Read more

    The 25 September 2018 by   Thefoodiecoupleblog
    FOOD & DRINK, RECIPES
  • Your Eye Drops Can Kill You

    Your Drops Kill

    Anything can be a poison, it all depends on the dose. This includes the drops you use to clear your eyes. The active, and dangerous, ingredient in many of... Read more

    The 25 September 2018 by   Dplylemd
    BOOKS, CULTURE, HEALTH, MEDICINE
  • The Wood Brothers: "River Takes the Town" & "Happiness Jones" Dutch TV Live...

    Wood Brothers: "River Takes Town" "Happiness Jones" Dutch Live Videos

    Watch roots trio The Wood Brothers perform River Takes the Town and Happiness Jones two tracks from their latest album One Drop Of Truth for Dutch music show... Read more

    The 25 September 2018 by   Hctf
    ENTERTAINMENT, MUSIC
  • Opera Review: Falling Down

    Opera Review: Falling Down

    The Met opens with a disastrous Samson et Dalila. by Paul J. Pelkonen A world of toil: Robert Alagna does hard time in Samson et Dalila. Photo by Ken Howard ©... Read more

    The 25 September 2018 by   Superconductor
    CULTURE, THEATRE & OPERA
  • Could Neanderthals Speak? Implications of FOXP2

    FOXP2 is one of the most famous genes out there; notable for containing two mutations linked to language in humans. These mutations are also in Neanderthals,... Read more

    The 25 September 2018 by   Reprieve
    BIOLOGY, SCIENCE
  • Diet Doctor Podcast #3 – Dr. Jeffry Gerber and Ivor Cummins

    Ivor Cummins: Great to be here, Bret. Dr. Jeffry Gerber: Thanks, Bret. Bret: The first thing I want to talk to you about is I learned from you guys you have t... Read more

    The 25 September 2018 by   Dietdoctor
    DIET & WEIGHT, HEALTH, HEALTHY LIVING, MEDICINE

Magazines