Working with Java data types Flashcards

1
Q

Which of the following statements are true:

  1. method length() of String class is a final method.
  2. You can make mutable subclasses of the String class.
  3. StringBuilder extends String.
  4. StringBuilder is a final class.
  5. String class is not final.
A

1, 4

  • StringBuilder extends Object.
  • String, StringBuilder and StringBuffer are all final classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of these expressions will return true:

  1. “hello world”.equals(“hello world”)
  2. “hello world”.equals(“hello world”)
  3. “hello”.concat(“ world”).trim().equals(“hello world”)
  4. “hello”.concat(“ world”).trim().equals(“hello world”)
  5. “Hello world”.toLowerCase( ).equals(“hello world”)
A

1, 2, 3, 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
True/false:
Wrapper objects are always immutable:
Integer dataWrapper = new Integer(5);
A

True

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

True/false: The following is valid:

unsigned byte b = 0;

A

False

- There is no unsigned keyword in Java

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

True/false: The following is valid:

int 2ndArgument = Integer.parseInt(args[2]); //3

A

False

- an identifier name can’t start with a digit. Note: it may start with an underscore.

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

Which of these are not part of the StringBuilder class:

  1. trim( )
  2. ensureCapacity(int )
  3. append(boolean)
  4. reverse( )
  5. setLength(int)
A

1.

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

Which of the following is not a primitive data value in Java:

  1. “x”’
  2. ‘x’
  3. 10.2F
  4. Object
  5. false
A

1, 4

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

True/false: Constructors can’t be marked as final

A

True

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

True/false: Any class can be declared abstract even if it does not have any abstract method.

A

True

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

True/false: Variables cannot be declared synchronized.

A

True

- Only methods can be declared synchronized.

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

True/false: Static methods can always refer to non-static/instance members

A

False.

- (this includes fields and methods).

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

True/false: An integer can be assigned to a double but not vice versa.

A

True

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

True/false: The charAt( ) method can take a char value as an argument.

A

True

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

True/false: The charAt( ) method returns a Character object.

A

False

- it returns char

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
The following compiles:
class MyString extends String{ 
 MyString(){ super(); }
}
A
False
- String is a final class and can't be extended
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True/false: the following is valid:
char c = s;
s = c;

A

False.
- Not all short values are valid char values, and neither are all char values valid short values, Both lines won’t compile.