Final Exam Asessment Portion

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Protected class members are denoted in a UML diagram with the symbol

#

What will be the tokens in the following statement?StringTokenizer strToken = new StringTokenizer("123-456-7890","-", true);

123,456,7890, and-

In the following statement, which is the superclass?public class ClassA extends ClassB implements ClassC

ClassB

In the following statement, which is the interface?public class ClassA extends ClassB implements ClassC

ClassC

Look at the following code and determine what the call to super will do.public class ClassB extends ClassA{public ClassB(){super(10);}}

It will call the constructor of ClassA that receives an integer as an argument

Which of the following is true about protected access?

Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package

In a class hierarchy

The more general classes are toward the top of the tree and the more specialized are toward the bottom

Two ways of concatenating two Strings are

Use the concat() method or use the + between the two Strings

To use the StringTokenizer class you must have the following import statement.

import java.util.StringTokenizer;

To convert the string, str = "285" to an int, use the following statement

int x = Integer.parseInt(str);

Look at the following code. Which line will cause a compiler error?Line 1 public class ClassALine 2 {Line 3 public ClassA() {}Line 4 public final int method1(int a){}Line 5 public double method2(int b){}Line 6 }Line 7 public ClassB extends ClassALine 8 {Line 9 public ClassB(){}Line 10 public int method1(int b){}Line 11 public double method2(double c){}Line 12 }

10

The no-arg constructor for a StringBuilder object gives the object enough storage space to hold this many characters.

16 characters

For the following code, how many times would the while loop execute?StringTokenizer strToken =new StringTokenizer("Ben and Jerry's ice cream is great.");while (strToken.hasMoreTokens()){System.out.println(strToken.nextToken());}

7

Assuming that str is declared as follows,String str = "RSTUVWXYZ";what value will be returned from str.charAt(5)?

W

What will be the value of str after the following statements are executed?StringBuilder str =new StringBuilder("We have lived in Chicago, " + "Trenton, and Atlanta.");str.replace(17, 24, "Tampa");

We have lived in Tampa, Trenton, and Atlanta

In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the spaces or other characters is

delimeter

What is the value of str after the following code has been executed?String str;String sourceStr = "Hey diddle, diddle, the cat and the fiddle";str = sourceStr.substring(12,17);

diddl

To convert the string, str = "285.74" to a double and store it in the variable x, use the following statement

double x = Double.parseDouble(str);

Look at the following code. What is missing from ClassA?Line 1 public interface MyInterfaceLine 2 {Line 3 int FIELDA = 55;Line 4 public int methodA(double);Line 5 }Line 6 public class ClassA implements MyInterfaceLine 7 {Line 8 FIELDA = 60;Line 9 public int methodB(double) { }Line 10 }

it doe snot override methodA

What is wrong with the following code?public class ClassB extends ClassA{public ClassB(){super(40);System.out.println("This is the last statement " +"in the constructor.");}}

nothing is wrong with the code

If you do not provide an access specifier for a class member, the class member is given this access by default.

package

When declaring class data members, it is best to declare them as

private members

In an interface all methods have

public access

Which of the following statements correctly specifies three interfaces

public class ClassA implements Interface1, Interface2, Interface3

Which of the following statements declares Salaried as a subclass of PayType?

public class Salaried extends PayType

What would be the results of executing the following code?StringBuilder str = new StringBuilder("Little Jack Horner ");str.append("sat on the ");str.append("corner");

str would equal "Little Jack Horner sat on the corner"

What would be the results of executing the following code?StringBuilder str = new StringBuilder(12);str.append("The cow");str.append(" jumped over the ");str.append("moon.");

str would equal "The cow jumped over the moon."

What is wrong with the following code?public class ClassB extends ClassA{public ClassB(){int init = 10;super(40);}}

the call to the method super must be the first statement in the constructor

Look at the following code.Integer myNumber;myNumber = 5;Which of the following is true about the second statement?

the statement performs autoboxing

Look at the following code.Integer myNumber = new Integer(5);int var = myNumber;Which of the following is true about the second statement?

the statement performs unboxing

Look at the following code.Line 1 public class ClassALine 2 {Line 3 public ClassA() {}Line 4 public void method1(int a){}Line 5 }Line 6 public class ClassB extends ClassALine 7 {Line 8 public ClassB(){}Line 9 public void method1(){}Line 10 }Line 11 public class ClassC extends ClassBLine 12 {Line 13 public ClassC(){}Line 14 public void method1(){}Line 15 }Which method will be executed as a result of the following statements?ClassB item1 = new ClassA();item1.method1();

this is an error and will cause the program to crash

In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the data items is

token

What will be the value of matches after the following code is executed?boolean matches;String[] productCodes = {"456HI345", "3456hj"};matches = productCodes[0].regionMatches(true, 1,productCodes[1], 2, 3);

true

Look at the following code.Line 1 public class ClassALine 2 {Line 3 public ClassA() {}Line 4 public void method1(){}Line 5 }Line 6 public class ClassB extends ClassALine 7 {Line 8 public ClassB(){}Line 9 public void method1(){}Line 10 }Line 11 public class ClassC extends ClassBLine 12 {Line 13 public ClassC(){}Line 14 public void method1(){}Line 15 }Which method1 will be executed as a result of the following statements?ClassA item1 = new ClassC();item1.method1();

Line 14

If ClassA is derived from ClassB, then

Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA

To convert the int variable, number to a string, use the following statement.

String str = Integer.toString(number);

Which of the following statements will print the maximum value a double variable may have?

System.out.println(Double.MAX_VALUE);

Which of the following statements will print the maximum value an int variable may have?

System.out.println(Integer.MAX_VALUE);

What will be the tokens in the following statement?StringTokenizer strToken = new StringTokenizer("January 1, 2008", ", ", true);

The token will be: January space 1 , space 2008

If a superclass does not have a default constructor,

Then a class that inherits from it, must call one of the constructors that the superclass does have

What will be printed after the following code is executed?String str = "abc456";int m = 0;while ( m < 6 ){if (Character.isLetter(str.charAt(m)))System.out.print(Character.toUpperCase(str.charAt(m)));m++;}

ABC

What will be the value of matches after the following code has been executed?boolean matches;String str1 = "The cow jumped over the moon.";String str2 = "moon";matches = str1.endsWith(str2);

False

In UML diagrams, inheritance is shown

With a line that has an open arrowhead at one end that points to the superclass

If ClassC is derived from ClassB, which is derived from ClassA, this would be an example of

a chain of inheritance

A protected member of a class may be directly accessed by

all of the above

If a class contains an abstract method,

all of the above

What does the following statement do?Float number = new Float(8.8);

all of the above

using the StringBuilder class's insert method, you can insert

all of the above

All fields declared in an interface

are final and static


Set pelajaran terkait

Speech 1315 Check Up Quizzes 1-21

View Set

The Constitution of the Republic of the Philippines

View Set

Combo with "Combo E-Commerce Exam 2" and 27 others

View Set

Unit 5: Methods of Transferring Title

View Set

Ch. 14 The Brain Connect Assignments

View Set

Aplia 3.1 formal and informal fallacies

View Set

Maryland Motorcycle Learners Permit Test

View Set

UIL Social Studies 2023-2024: Related Terms

View Set