import java.util.*; public void display() { List<Integer> nums = new ArrayList<> (); }
{ private int num; }
private String name = “John”; public void display() { System.out.print(name); }
Question 7
You have been asked to develop a Java program that prints the elements of an array in reverse order. Which looping statement cannot be used to meet the requirement?
enhanced for
standard for
while
do-while
Question 8
Given the code fragment: Which statement is true?
The code results in a compilation error. To make it compile, insert at line n1: import java.lang.Math; import java.lang.Random;
The code compiles successfully
The code results in a compilation error. To make it compile, insert at line n1: import java.lang; import java.util;
The code results in a compilation error. To make it compile, insert at line n1: import java.util.*;
Question 9
Given the code fragment: What is the result?
pen pencil erasers paper
paper pen pencil erasers
A compilation error occurs.
A runtime exception is thrown.
Question 10
Given the code fragment: Which code fragment, when inserted at line n1, enables the code to print Java Programming:1?