Computer Applications
Which of the following String methods has integer argument?
(i) length
(ii) substring
(iii) indexOf
(iv) charAt
- Only (ii)
- (i) and (iv)
- (ii) and (iv)
- (iii) and (iii)
Answer
(ii) and (iv)
Reason — The substring(int beginIndex) and charAt(int index) methods both take an integer argument to specify a position within the string. The substring method returns a part of the string starting from the given index, while charAt returns the character at the specified index.
Related Questions
Sham was asked to encode a string S, by replacing the letter E with #. Select the appropriate statement:
- S.replace('#','E')
- S.replace('E')
- S.replace('E', '#')
- S.replace('#')
When the String
mis compared ton, the result obtained is greater than zero. Which of the following is true?mcomes before n in the dictionary.ncomes beforemin the dictionary.mandnare equal.mandnhave the same length.
Assertion: Property by virtue of which one class acquires the properties of another class is termed as Inheritance.
Reason: Inheritance promotes reusability.
- Assertion is true, Reason is false.
- Assertion is true, Reason is true.
- Assertion is false, Reason is false.
- Assertion is false, Reason is true.
Which of the following is NOT true for polymorphism?
- All methods have the same name.
- Methods are invoked based on the arguments.
- Methods should have the same number and the same type of arguments.
- It is a principle of OOPs.