Sie sind auf Seite 1von 15

Which implementation of the List interface produces the slowest access to an element in the middle of

the list by means of an index?

class M {

public static void main(String[] s) {

String s1 = new String("ABCDEFG"), s2 = new String("EFGHIJ");

String s3 = s1.substring(4,7), s4 = s2.substring(0,3);

System.out.println((s3 == s4) + "," + (s3 + s4).equals(s4 + s3));

What is the result of attempting to compile and run the program?

•Each element/value pairs.

• Duplicate entries replace old entries.

• Entries are sorted using a Comparator or the Comparable interface.

Which of these classes provides the specified features?


class B {

public static void main (String args[]) {

Byte b1 = new Byte(1); // 1

Byte b2 = new Byte('2'); // 2

Byte b3 = new Byte("3"); // 3

byte i1 = b1.byteValue()+b2.byteValue()+b3.byteValue(); // 4

System.out.print(i1);

class M {

public static void main(String[] args) {

String s1 = "A", s2 = "a", s3 = "b";

s1.toLowerCase(); s3.replace('b','a');

System.out.print((s1.equals(s2)) + "," + (s2.equals(s3)));


}

What is the result of attempting to compile and run the program?

class M {

static void m1(StringBuffer s1) {

s1 = s1.append("B"); System.out.print(s1);

static void m2(StringBuffer s1) {

s1.append("C"); System.out.print(s1);

public static void main(String[] s) {

StringBuffer s1 = new StringBuffer("A");

m1(s1); m2(s1);

System.out.print(s1);

What is the result of attempting to compile and run the program?


class M {

public static void main(String[] s) {

String s1 = "1", s2 = "2", s3 = s1 + s2;

s1 += s2; s3 += s1;

System.out.println(s3);

What is the result of attempting to compile and run the program?

class M {

public static void main (String[] args) {

String s1 = "ABC";

StringBuffer s2 = new StringBuffer(s1);


System.out.print(s2.equals(s1) + "," + s1.equals(s2));

What is the result of attempting to compile and run the program?

class A {

public static void main(String[] args) {

Boolean b1 = new Boolean(true); // 1

Boolean b2 = new Boolean(false); // 2

Boolean b3 = new Boolean(TRUE); // 3

Boolean b4 = new Boolean(FALSE); // 4

Boolean b5 = new Boolean("TrUe"); // 5

Boolean b6 = new Boolean("fAlSe"); // 6

Compile-time errors are generated at which lines? (Multi choice)


class M {

static void m1(StringBuffer s1) {

s1 = s1.append("B"); System.out.print(s1);

static void m2(StringBuffer s1) {

s1.append("C"); System.out.print(s1);

public static void main(String[] s) {

StringBuffer s1 = new StringBuffer("A");

m1(s1); m2(s1);

System.out.print(s1);

What is the result of attempting to compile and run the program?


class M {

public static void main(String[] s) {

String s1 = "A", s2 = " B ", s3 = "C";

s2.trim(); s3.concat("D");

System.out.print(s1 + s2 + s3);

What is the result of attempting to compile and run the program?

• Entries are not organized as key/value pairs.


• Duplicate entries are rejected.

Which interface of the java.util package offers the specified behavior?

class B {

public static void main (String[] args) {

byte b1 = 11;

System.out.print(new Integer(b1).equals(new Integer(b1)) + ",");

System.out.print(new Integer(b1).equals(new Short(b1)) + ",");

System.out.print(new Integer(b1).equals(new Byte(b1)));

What is the result of attempting to compile and run the program?


class ColorException extends Exception {}

class WhiteException extends ColorException {}

class White {

void m1() throws ColorException {throw new WhiteException();}

void m2() throws WhiteException {}

public static void main (String[] args) {

White white = new White();

int a,b,d,f; a = b = d = f = 0;

try {white.m1(); a++;} catch (ColorException e) {b++;}

try {white.m2(); d++;} catch (WhiteException e) {f++;}

System.out.print(a+","+b+","+d+","+f);

What is the result of attempting to compile and run the program?


• Stores key/value pairs.

• Allows null elements, keys, and values.

• Duplicate entries replace old entries.

• Entries are not sorted.

Which of these classes provides the specified features?

class E {

public static void main (String[] args) {

Byte b1 = new Byte("1"), b2 = new Byte("1");

System.out.print((b1==b2)+","+(b1.equals(b2)));

What is the result of attempting to compile and run the program?

class A {

public static void main (String[] args) {


Error error = new Error();

Exception exception = new Exception();

System.out.print((exception instanceof Throwable) + ",");

System.out.print(error instanceof Throwable);

What is the result of attempting to compile and run the program?

class A {A() throws Exception {}} // 1

class B extends A {B() throws Exception {}} // 2

class C extends A {C() {}} // 3

Which of the following statements are true? (Multi choice)

class D {

public static void main (String[] args) {

Boolean b1 = new Boolean("trUE"); // 1

Boolean b2 = new Boolean("What's This?"); // 2

Boolean b3 = new Boolean(null); // 3

System.out.print(b1 + "," + b2 + "," + b3);


}

What is the result of attempting to compile and run the program?

• Entries are organized as key/value pairs.

• Duplicate entries replace old entries.

Which interface of the java.util package offers the specified behavior?

class M {

static void m1(StringBuffer s1) {

s1.append("B"); System.out.print(s1);

static void m2(StringBuffer s1) {


s1 = new StringBuffer("C"); System.out.print(s1);

public static void main(String[] s) {

StringBuffer s1 = new StringBuffer("A");

m1(s1); m2(s1);

System.out.print(s1);

What is the result of attempting to compile and run the program?

• Each element must be unique.

• Contains no duplicate elements.

• Elements are not key/value pairs.

• Accessing an element can be almost as fast as performing a similar operation on an array.

Which of these classes provides the specified features?