proprofs Flashcards

1
Q

Which of the following declarations are correct? (Choose TWO)
1.boolean b =TRUE;

  1. byte b = 256;
  2. String s =”null”;
  3. int i = newInteger(“56”);
A

3

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
Consider the following code and select the correct output:
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 public class Lists 
{
    public static void main(String[] args) 
      {
          List list=new ArrayList(); 
          list.add("1"); list.add("2"); 
          list.add(1, "3");
          List list2=new LinkedList(list); 
          list.addAll(list2); list2 =list.subList(2,5); 
          list 2.clear(); System.out.println(list);
       }
 }

[1,3,2]
[1,3,3,2]
[1,3,2,1,3,2]
[3,1,2]

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
Which statements, when inserted at (1), will not result in compile-time errors?
 public class ThisUsage 
{
     int planets;
     static int suns;
     public void gaze() 
  {
       int I; 
   // (1) INSERT STATEMENT HERE } } i =this.planets; i = this.suns; this = newThisUsage(); this.suns =planets;
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
Given:
 import java.util.*;
 public class LetterASort
{
     public static void main(String[] args)
     {
        ArrayList strings = new ArrayList(); 
        strings.add("aAaA");
        strings.add("AaA");
        strings.add("aAa");
        strings.add("AAaa");
        Collections.sort(strings);
       for (String s : strings)
       {
              System.out.print(s + " "); 
       }
   }
 }

What is the result?
Compilation fails. aAaA aAa AAaa AaA AAaa AaA aAa aAaA AaA AAaa aAaA aAa

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly