Log in
Sign up for FREE
arrow_back
Library

Array of Ref Quiz

star
star
star
star
star
Last updated almost 2 years ago
10 questions
1
1
1
1
1
1
1
1
1
1
Question 1
1.

What is output by the code below?

String[] x;
x = new String[6];
System.out.println( x[2] );

Question 2
2.

What is output by the code below?

String[] x;
x = new String[7];
x[1] = "go";
x[4] = "up";
x[2] = "by";
System.out.println( x[1] );

Question 3
3.

What is output by the code below?

String[] x;
x = new String[7];
x[1] = "go";
x[4] = "up";
x[2] = "by";
System.out.println( x[0] );

Question 4
4.

What is output by the code below?

String[] x;
x = new String[7];
x[1] = "go";
x[4] = "up";
x[2] = x[4];
x[4] = null;
System.out.println( x[2] );

Question 5
5.

What is output by the code below?

String[] x;
x = new String[7];
x[1] = "go";
x[4] = "up";
x[2] = x[4];
x[4] = null;
System.out.println( x[2].length() );

Question 6
6.

Consider the following class definitions.

public class Cat
{
private String name:
private int age;
public Cat( String n, int a )
//implementation not shown

public String getName()
//implementation not shown

public int getAge()
//implementation not shown

//other methods not shown
}
//client code in another class
Cat[] bunch = new Cat[5];
System.out.println( bunch[0] );

Question 7
7.

Consider the following class definitions.

public class Cat
{
private String name:
private int age;
public Cat( String n, int a )
//implementation not shown

public String getName()
//implementation not shown

public int getAge()
//implementation not shown

//other methods not shown
}
//client code in another class
Cat[] bunch = new Cat[5];
System.out.println( bunch.length );

Question 8
8.

Consider the following class definitions.

public class Cat
{
private String name:
private int age;
public Cat( String n, int a )
//implementation not shown

public String getName()
//implementation not shown

public int getAge()
//implementation not shown

//other methods not shown
}
//client code in another class
Cat[] bunch = new Cat[5];
bunch[0] = new Cat("rocket", 8);
System.out.println( bunch[0].getAge() );

Question 9
9.

Consider the following class definitions.

public class Cat
{
private String name:
private int age;
public Cat( String n, int a )
//implementation not shown

public String getName()
//implementation not shown

public int getAge()
//implementation not shown

//other methods not shown
}
//client code in another class
Cat[] bunch = new Cat[5];
bunch[0] = new Cat("rocket", 8);
bunch[3] = new Cat("sam", 15);
bunch[4] = new Cat("ben", 12);
System.out.println( bunch[3].getAge() );

Question 10
10.

Consider the following class definitions.

public class Cat
{
private String name:
private int age;
public Cat( String n, int a )
//implementation not shown

public String getName()
//implementation not shown

public int getAge()
//implementation not shown

//other methods not shown
}
//client code in another class
Cat[] bunch = new Cat[5];
bunch[0] = new Cat("rocket", 8);
bunch[3] = new Cat("sam", 15);
bunch[4] = bunch[3];
bunch[3] = bunch[0];
System.out.println( bunch[4].getAge() );