Answered step by step
Verified Expert Solution
Link Copied!

Question

...
1 Approved Answer

Java Project Create a NetBeans project for this activity. Test Stem / Question Choices 1: Create a new class with attributes name and address. Both

Java Project

  • Create a NetBeans project for this activity.

Test Stem / Question

Choices

1: Create a new class with attributes name and address. Both data type will be String. Create a constructor and assign the parameters to the attributes.

Now override the toString() method.

Is this possible?

A: Yes.

B: No.

C: In some cases where the attributes are only strings.

D: Yes, as long as you explicitly extends Object class.

2: Create a class with the main method and create an instance of the class that you created in Test Stem

1. What method can you call to get the hashCode of your class?

A: hashCode()

B: getHash();

C: getHashCode();

D: toHashCode();

3: What is the return type of the hash code ?

A: int

B: byte

C: byte[]

D: String

4: Create an instance of the string in your test class and assign a value. Which of the following operators can be used in conjunction with a string object?

  1. +
  2. -
  3. &
  4. .
  5. +=

A: a, d & e

B: a & e

C: d & e

D: b, d & e

5: Supposed that we have a string with a value This is my string..

Which method can be used to extract a specific word from the given string?

A: substring

B: concat

C: extract

D: get

6: Supposed that we have a string with a value This is my string..

Which expression can be used to extract the word my from the given string?

A: string.substring(8, 10)

B: string.get(my)

C: string.extract(my);

D: string.concat(8, 2)

7: Now create an String and assign a value with spaces in the beginning, end and middle.

Try out the method trim(). What does it do?

A: It removes all the leading and trailing spaces in the string.

B: It removes all the spaces in the string; basically combining all the words in the string

C: It removes all the leading spaces of the string

D: It trims the trailing spaces of the string.

8: In your test class with main method, instantiate a string buffer with the initial value of hello.

How will you be able to do that?

A: StringBuffer sb = new StringBuffer("hello");

B: StringBuffer sb = new StringBuffer();

sb.initialize(hello);

C: StringBuffer sb = new StringBuffer().init(hello);

D: StringBuffer sb = hello;

9: In your test class with main method, instantiate a string buffer with the initial value of hello.

Use the method setLength with parameter 2. Print the string representation of the StringBuffer using toString(). What is the result?

A: It changed the size of the string buffer and printed he

B: it added two additional blank characters in the initial value.

C: Nothing happened since the initial length is bigger than the value assign to the setLength method.

D: It reduces the size of the StringBuffer by 2 and printed hel

10: Which method is not defined in the StringBuffer class?

  1. appends
  2. codePointCount
  3. insert
  4. lastIndexOf

A: A only

B: A & b

C: B only

D: D only

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started