Working with Java data types Flashcards
Which of the following statements are true:
- method length() of String class is a final method.
- You can make mutable subclasses of the String class.
- StringBuilder extends String.
- StringBuilder is a final class.
- String class is not final.
1, 4
- StringBuilder extends Object.
- String, StringBuilder and StringBuffer are all final classes
Which of these expressions will return true:
- “hello world”.equals(“hello world”)
- “hello world”.equals(“hello world”)
- “hello”.concat(“ world”).trim().equals(“hello world”)
- “hello”.concat(“ world”).trim().equals(“hello world”)
- “Hello world”.toLowerCase( ).equals(“hello world”)
1, 2, 3, 5
True/false: Wrapper objects are always immutable: Integer dataWrapper = new Integer(5);
True
True/false: The following is valid:
unsigned byte b = 0;
False
- There is no unsigned keyword in Java
True/false: The following is valid:
int 2ndArgument = Integer.parseInt(args[2]); //3
False
- an identifier name can’t start with a digit. Note: it may start with an underscore.
Which of these are not part of the StringBuilder class:
- trim( )
- ensureCapacity(int )
- append(boolean)
- reverse( )
- setLength(int)
1.
Which of the following is not a primitive data value in Java:
- “x”’
- ‘x’
- 10.2F
- Object
- false
1, 4
True/false: Constructors can’t be marked as final
True
True/false: Any class can be declared abstract even if it does not have any abstract method.
True
True/false: Variables cannot be declared synchronized.
True
- Only methods can be declared synchronized.
True/false: Static methods can always refer to non-static/instance members
False.
- (this includes fields and methods).
True/false: An integer can be assigned to a double but not vice versa.
True
True/false: The charAt( ) method can take a char value as an argument.
True
True/false: The charAt( ) method returns a Character object.
False
- it returns char
The following compiles: class MyString extends String{ MyString(){ super(); } }
False - String is a final class and can't be extended