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 :

  • Book Review The Almanac A Seasonal Guide to 2019

    Book Review Almanac Seasonal Guide 2019

    The Almanac - A Seasonal Guide to 2019 by Lia Leendertz, when I started to read this little book of loveliness I realised it was not a book you read and put dow... Read more

    The 09 December 2018 by   Angela
    FOOD & DRINK, RECIPES
  • Savory Vegan Succotash

    Savory Vegan Succotash

    Sufferin’ Vegan Succotash!  Look what we have here! That’s right! Succotash is a real THING and not just something a funny cartoon character says. Bonus points... Read more

    The 09 December 2018 by   Chuck Underwood
    FOOD & DRINK, HEALTH, HEALTHY LIVING, LIFESTYLE, VEGETARIAN & VEGAN
  • Metabolic Health and Nutrition Conference – Part 3

    Metabolic Health Nutrition Conference Part

    I earlier this year attended a conference in Seattle, WA, (USA) titled " Metabolic Health and Nutrition Across the Life Span." The headlining presenters were Dr... Read more

    The 09 December 2018 by   Dietdoctor
    DIET & WEIGHT, HEALTH, HEALTHY LIVING, MEDICINE
  • "If" Then, and "If" Now

    "If" Then,

    By Elizabeth PrataAmy Carmichael was a missionary to India, arriving in 1895 to Dohnavur, just 30 miles from India's southern tip. Once in South India she... Read more

    The 09 December 2018 by   Elizabethprata
    SOCIETY, SPIRITUALITY
  • Airbus A330-200, Thomas Cook Airlines

    Airbus A330-200, Thomas Cook Airlines

    @ San Francisco International Airport, CA October 2018 Starting in May 2017, Thomas Cook began operating two flights per week between SFO and Manchester, UK... Read more

    The 09 December 2018 by   Htam
    PHOTOGRAPHY, SOCIETY
  • Caroling Party

    Caroling Party

    Last night we hosted our fourth annual caroling party. I'm not a big Christmas gift-giving person, so our gift to everyone is doughnuts, hot chocolate, hot... Read more

    The 09 December 2018 by   Sherwoods
    FAMILY, PARENTING
  • Struggling to Afford Insulin

    Struggling Afford Insulin

    People who need insulin for their type 1 or type 2 diabetes are skimping on the shots because the drug has become so expensive. A study this week in the... Read more

    The 09 December 2018 by   Dietdoctor
    DIET & WEIGHT, HEALTH, HEALTHY LIVING, MEDICINE

Magazines