0% found this document useful (0 votes)
95 views17 pages

Class 10 MCQ

The document contains multiple-choice questions and answers related to computer applications, specifically focusing on Java programming concepts. It covers topics such as keywords, data types, operators, object-oriented programming principles, and method definitions. Each question is followed by an explanation to clarify the correct answer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views17 pages

Class 10 MCQ

The document contains multiple-choice questions and answers related to computer applications, specifically focusing on Java programming concepts. It covers topics such as keywords, data types, operators, object-oriented programming principles, and method definitions. Each question is followed by an explanation to clarify the correct answer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

computer Applications

revision of Class IX Syllabus


Multiple Choice Questions
1. Among the following which is a keyword:
(a) every (b) all (c) case (d) each
A ns : (c) case

Explanation :
Among the options, "case" is keyword commonly used in programming to define conditions or
branches in a switch-case statement.
2. Among the following which is not a feature supported by java?
( a ) I nh e ri t a nc e (c) Multiple Inheritance
( b) C onst ruct or overl oadi ng (d) Polymorphism
Ans. (c) Multiple Inheritance
Explanation :
Java does not support multiple inheritance. Multiple inheritance is implemented using interfaces in java
3. Among the following, which is not a primitive data type?
(a) enum (b) Short (c) Byte (d) Int
Ans. (a) enum
Explanation
An enum is a type that has a fixed list of possible values, which is specified when the enum is created.
4. Modulus operator, %, can be applied to.
(a) Integers (c) Both Integers and floating - point numbers
( b ) F l o a t i ng- po i nt nu m be r s (d) None of the above
Ans. (c) Both Integers and floating - point numbers
Explanation
Modulus operator can be applied to both integers and floating point numbers.
5. Relational operators are :
( a ) Un a ry op e ra t or (c) Ternary operator
( b) Binary operator (d) Conditional operator
Ans. (b) Binary operator
Explanation :
Relational operator compares two operands and returns true or false.
6. Ternary operator is a:
(a) logical operator (c) relational operator
(b) arithmetic operator (d) conditional operator
Ans. (d) conditional operator
Explanation
The conditional operator is the only ternary operator in Java that works like an if-else statement and
returns true or false.
7. The output of Math.round(6.6) + Math.ceil(3.4) is:
(a) q.0 (b) 11.0 (c) 10.0 (d) 11

Ans. (b) 11.0


Explanation
Working: 7 + 4.0 = 11.0
8.How many times 'Hello' is printed?
Public static void main(String args[])

for(i = 0;i<5;i++)

System.out.println("hello"); break;

(a) 5 (b ) 4 (c) 1 (d) 0


Ans. (c) 1
Explanation :
It is printed one time only because break; will terminate the current loop.
9. Size of integer in Java Programming is
(a) 8 Bytes (b) 1 Bytes (c) 2 Bytes (d) 4 Bytes
Arts. (d) 4 Bytes
Explanation :
The size of integer in Java Programming is 4 Bytes.
10. What is the way to come out of or Quit any Loop suddenly?
( a ) q ui t ; s t a te m e n t (c) break; statement
( b) l ea ve; Sta te me nt (d) continue; Statement
Ans. (c) break; statement
11. The expression Math.pow(2,-2) + Math.floor(12.59) returns ?
(a) 12.0 (b) 12.25 (c) 14.5 (d) None of these
Ans. (b) 12.25
Explanation :
Math.pow(2,-2) gives 0.25 and Math.floor(12.59) gives 12.0 . Sum of these gives 12.25
12. Give the value of the following expression 6-2+10%4+7
(a) 13 (b) 10 (c) 12 (d) 14
Ans. (a) 13
Explanation :
aZilfa94004/liwarrt•Mo.iterabdia

Perform modulus operation first.as it has got a higher priority.


= 6-2+2+7
= 4+2+7
=13
13.What will be the value of x after executing the following statement?
x=(x<y) ? (y+x) : (y-x);
If 'int x=15; y=20;
(a) 5 (b) 15 (c) 25 (d) 35
Ans. (d) 35
Explanation :
x= 15, y= 20;
x = (x<y)?(y+x):(y-x); //since x
<y
(y+x) will be executed so the
answer is 35
14.The operator that deallocates the memory occupied by an object and deletes the object is ________
(a) remove (b) deallocate (c) delete (d) None of these
Arts. (c) delete
1 5 . G i v e t h e o ut p ut of t h e f o l l o w i n g :
int a, b =10 ; a = 15/3 *b ;
System.out.println("a = " + a);
(a) 50 (b) 49 (c) 53 (d) 52
Ans. (a) 50

Animal Class I

16.Which concept of OOP is shown in the


figure : (a) Objects (b) Class (c) Data Hiding (d) Data Security
Ans. (a) Objects
Explanation :
In the figure , multiple objects of the animal class are created , showing that Animal is the class and the
different animals are its instances.
17. A string is:
(a) Mutable (c) Partially mutable
(b) Non-mutable (d) None of these
Ans. (b) Non-mutable
Explanation : a zo

A string is a immutable data type. It cannot be changed.


18. int result='B', what is the value of result ?
(a) 42 (b) ‘B’ (c) 66 (d) 98
Ans. (c) 66
Explanation :
Since the ASCII code of 'B'is 66 , the integer variable result will store 66.
19. Assertion(A): Both java bytecode and the JVM are responsible for java's platform independence.
Reason(R): The bytecode is prepared in an universally acceptable format and the underlying JVM makes
the bytecode understandable to the specific platform.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion(A).
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is false and Reason (R) is true
Ans. (c) Assertion (A) is true and. Reason (R) is false
Explanation
The java byte code is an object code that is written in such a format that it can be understood by all
machines. The JVM makes the bytecode understandable to the underlying platform.

Class as the Basis of all Chapter


Computation

L
Multiple Choice Questions
1.

Name the feature of java depicted in the above picture.


(a) Encapsulation (b) Inheritance (a) Abstraction (b) Polymorphism

Ans. (b) Inheritance


Explanation :
In inheritance, the child inherits the properties of its parents, which is shown in the picture.
2. Which of the following is not a feature of OOPS?
(a) Inheritance (c) Polymorphism
(b) Function Overloading (d) All are OOPS Features
Ans. (d) All are OOPS Features
3. A non static method is also called :
(a) Class method (c) Constant method
(b) Instance method (d) Instance variable(c) Encapsulation (d) Abstraction
Ans. (b) Instance method
4. "One thing in many different forms" goes with the OOPS concept.
(a) Polymorphism (b) Inheritance
Ans. (a) Polymorphism
5. A static method is also called a :
(a) Instance fu nction (a) C l a s s m e t h o d
(b) Defi ned fun ct ion (b) Fi x ed fu n ct i on
Ans. (c) Class method
6. A bundle of similar classes is called a
(a) Package (b) Group (c) Packed classes (d) None
Ans. (a) Package
7, Code reuse is implemented by :
(a) Abstraction (c) Inheritance
(b) Function overloading (d) P o l y m o r p h i s m
Anh. (c) Inheritance
27.

r:t

8. Which OOP concept is illustrated by the above figure


(a) Inheritance (b) Polymorphism
Ans. (b) Polymorphism
Explanation :
Polymorphism is one thing in many different forms. In the figure the same person is acting in
different forms in different places.
9. A non static method is also called :
(a) Class method (c) Constant method
( b ) I ns t a n ce m e t ho d (d) Instance variable (c) Inheritance (d) None of these
Ans. (b) Instance
method
Explanation :
Non static methods are also called Instance methods . They usually access instance variables but can
also access class variables.
10. The other name for messages of a class is :
(a) Methods (c) Instances
(b) Functions (d) Both (a) and (b)
Ans. (d) Both (a) and (b)
Explanation :
Methods and functions are the elements that pass messages from one class to other.

Chapter

User defined Methods


-

3
Multiple Choice Questions
1. A function name can begin with
(a) An alphabet (b) A digit (c) * Sign (d) Space
Ans. (a) An alphabet
2. An overloaded function is
(a) A function with same name but different return types
(b) A function with same name but different number of parameters
(c) A function with same name but different types of parameters
(d) Both (b) and (c)
Ans. (d) Both (b) and (c)
Explanation :
A function with the same name but different number of parameters or different types of parameters.
3. Assertion(A): call by value is known as pure method
Reason(R): The original value of variable does not change as operation is performed on copied values.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion(A)
(c) Assertion (A) is true and Reason (R) is false
(d) Assertion (A) is true and Reason (R) is false
Ans. (a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
4. Write output of following code:
void result(int num)

sum=0;
while(num>
0)

d=num%10;
if ( d%3==0)
sum=sum+d;

else sum=sum-d;
num=num/10;
System.out.println(sum+"");
void main()
{
result(6972);
}
(a) 6 (b) 9 (c) -9 (d) 10
Ans. (a) 6
Explanation :
The function extracts each digit and checks whether it is divisible by 3. If divisible it adds to the sum else
the digit is subtracted from sum. Hence -2 -7 + 9 + 6 = 6, since 2, 7 are not divisible by 3 and 9 ,6 are divisibe
by 3.
5. Which of the following declarations illustrate function overloading?
(a) int callme(int,int), int callme(int,float) (c) int callme(int,int), int callme(int,int,int)
(b) float callme(int,int), int callme(int,int) (d) both (a) and (c)
Arts. (d) both (a) and (c)
Explanation :
In function overloading the functions may be differentiated by number or type of parameters, which
is done in options (a) and (c)
6. Which statement is erroneous in the code below?
Def showdata() {//Line 1
//Line 2
System.out.println("Hello Python");
//Line3
}

(a) Line 1 (b) Line 2 (c) Line 3 (d) All are errors
Ans. (a) Line 1
Explanation
There is no keyword like Def in Java to define a function.

7. Assertion (A): Increment operator increases the value of an operand by 1.


Reason (R): Increment operator works on only variables as an operator.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion
(A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false
Ans. (b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion
(A)
Explanation :
The assertion is true as the increment operator increases the value of an operand by 1. However, the
reason is not entirely corrct as the increment operator can also work on variables. It's not limited to just
variables; it can also work on certain expression. Therefore, while both statements are true, the reason does
not fully explain the assertion.
8. Method which reverses a given number is:
(a) Impure method (c) Constructor
(b) Pure method (d) Destructor
Ans. (b) Pure method
Explanation :
The method of doing the reverse of a number will create a new number that will be the reverse of the
number but will not change the original number itself.
9. Invoking a method by passing the objects of a class is termed as:
(a) Call by refere nce (c) Ca l l b y m et h o d
(b) Call by v al ue (d) Call by constr uctor
Ans. (a) Call by reference
Explanation :
In passing a parameter as an object works as a call by reference because there exists only one copy of the
object shared in both the caller and called methods.
10. The correct statement to create an object named mango of class fruit:
(a) Fruit Mango= new filth(); (c) Mango fruit=new Mango();
(b) fruit mango = new fruit(); (d) fruit mango= new mango();
Ans. (b) fruit mango = new fruit();
Explanation :
The class name and the object name should be the same as mentioned in the question.
11. Assertion (A): Static method can access static and instance variables.
Reason (R): Static variable can be accessed only by static method.
(a) Assertion and Reason both are correct.
(b) Assertion is true and Reason is false.
(c) Assertion is false and Reason is true.
(d) Assertion and Reason both are false.
Ans. (d) Assertion and Reason both are false.

Chapter
Constructors

Multiple Choice Questions


- • • - - - -

1. Constructor overloading follows which principle of Object Oriented programming?


(a) Inheritance
( c ) Abstraction
( b ) Polymorphism ( d ) Encapsulation
Ans. (b) Polymorphism
Explanation :
Function overloading or constructor overloading is an example of polymorphism.
2. In derived class can constructors be overloaded?
(a) Yes if derived class has no constructor (c) No
(b) Yes (d) Both (a) and (b)
always
Ans. (c) No
Explanation :
The constructor must be having the same name as that of
a class.
4. Which principle in Object-Oriented programming is same name to all constructors. So, is the
followed during Java constructor overloading
(a) Polymorphism (c) Encapsulation
(b) Inheritance (d) None of these
Ans. (a) Polymorphism
Explanation :
Overloading of constructors requires you to specify the polymorphism principle of Oops.
5. Default constructor requires how many parameters?
(a) 3 (b) 0 ' (c) 2 (d) 1
Ans. (b) 0
Explanation :
Default constructors have no parameters, but they can have parameters with default values.
6. A method with the same name as of the class and with arguments and. no return data type is termed
(a) parmeterized constructor
(b) default constructor
(c) non-parameterised constructor
(d) wrapper class method
Ans. (b) default constructor
7. Assertion (A): Constructor is invoked at the time of instantiation of an
object.
Reason (R): Constructor cannot be called explicitly like a regular method in a program.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion
(A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false
Ans. (a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
Explanation :
Constructor can only be called at the time of object creation.

8. If the name of the class is "Yellow", what can be the possible name for its constructors?
(a) yellow (b) YELLOW (c) Yell (d) Yellow
Ans. (d) Yellow
Explanation :
Constructor will have the same name as that of the class itself.

9. A class can have ____________________ number of constructors.


(a) One (b) Two (c) Three (d) Multiple
Ans. (d) Multiple
Explanation :
A class can have any number of constructors to initialise the data members in different ways and by
different values.
10. A method with the same name as of the class and with no arguments and no return data type is
termed as:
(a) parameterized constructor (c) copy constructor
(b) default constructor (d) wrapper class method
Ans. (b) default constructor
Explanation :

A default constructor has same name as class and does not take any parameters.
11. Constructors can be overloaded on:
(a) Number of arguments (c) Return type
(b) Types of arguments (d) Both (a) and (b)
Ans. (d) Both (a) and (b)
Explanation :
By the concept of function overloading , functions can be overloaded by number or type of
parameters not by the return type.
12. Constructor generated by compiler is known as:
(a) copy constructor (c) static constructor
(b)default constructor (d) parameterized constructor
Anse (b) default constructor
Library classes Chapter
5
Multiple Choice Questions
1. Read the following text, and choose the correct answer:
A class encapsulate Data Members that contains the information necessary to represent the class
Member methods that perform operations on the data member.
What does a class encapsulate?
( a ) I n f o r m a t i o n an d o pe r a t i o n (c) Data members and information
( b) Da t a m e m ber s and M em b e r met ho d s (d) Member methods and operation
Ans. (b) Data members and Member methods
Explanation :
Encapsulation means wrapping up of data and functions into a single unit called class.

2. A wrapper converts :
(a) int to float (c) String to StringBuffer
(b) float to int (d) Primitive data type to object
Ans. (d) Primitive data type to object
Explanation :
In Java, primitive data types are passed by value, whether objects are passed by reference.
3. float f = 3.14; Here f is of type :
(a) Object (b) Primitive (c) Wrapper (d) None of these
Ans. (b) Primitive
Explanation :
Here, f is a simple variable of float primitive data type.
4. Find the odd one.
(a) Character (b) Byte (c) Integer (d) float
Ans. (d) float
Explanation :
All the others in the options (a), (b), (c) are Wrapper classes.
5. The statement that converts the string object s="400" to integer "s_int" is
(a) s _int=Int eger. parse(s); (c) s_int=Integer.parseInt(s);
(b) s _i n t =Int eg er . In t ( s) ; (d) s_int=integer.parseInt(s_int);
Ans. (c) s_int=Integer.parseInt(s);
Explanation :
The Integer class's parselnt() method converts a string to integer.
6. Which class is imported by the Character and Boolean wrapper classes ?
(a) Number (h) Object (c) Strin g (d) Float
Ans. (b) Object
Explanation :
The Object class is imported by the Character and Boolean wrapper class es .
7. The automatic conversion of a primitive data type to its corresponding wrapper object is called :
(a) Boxing (b) Autoboxing (c) Preboxing (d) ReverseBoxing
Ans. (b) Autoboxing
8. What is the method to check whether a character is a letter or digit?
(a) isDigif (char) (c) isLetterOrDigit(char)
(h) isLetterOrDigit() (d) isLETTERorDIGIT(char)
Ans. (c) isLetterOrDigit(char)
Explanation :
_isLetterOrDigit() ) checks whether the character is a letter or digit or none of them.
9.Boxing is :
(a) Converting the primitive data type from one type to another
(b) Converting wrapper class object to primitive data type
(c) Converting the primitive data types into its corresponding wrapper class object.
(d) None of th e above
Ans. (c) Converting the primitive data types into its corresponding wrapper class object.
Explanation :
..aLeVii.77.460.11MISMSZi

Boxing converts the primitive data types into its corresponding wrapper class object. For example from
int to Integer

10. _______ is the wrapper class for the char data type.
(a) Char (b) CHAR (c) CHARACTER (d) Character
Ans. (d) Character
Explanation :
The primitive data types have their corresponding wrapper classes . The wrapper class for char data type is
Character_
11. Select the odd option
(a) Boxing (c) Pre Increment
(b) Unboxing (d) Typecasting
Ans. (c) Pre Increment
Explanation :
Only Pre Increment is an arithmetic operation. All others are conversion operations.
12. The function that checks whether a character is a tab space or not.
(a) isTabSpa ce() (c) i s W hi t e Sp a ce( )
(b) i s S p a c e ( ) (d) isWHITESpace()
Ans. (c) isWhiteSpace()
Explanation :
The isWhiteSpace() function checks whether a character carries a tab or a white space
13. Each primitive data type belongs to a specific:
(a) block (c) wrapper class
(b) object (d) none of these
Ans. (c) wrapper class

Chapter
Encapsulation 6
Multiple Choice Questions

1. Access specifiers are used for :

1. If no access specifier is specified the default access specifier in Java is :


(a) Private (b) Public (c) Pro tected
Ans. (d) None of these (a) Re m o vi n g o bj e ct s
Explanation : (c) Renaming objects.

(b) Deallocating objects (d) Restricting accessibility of class members.


Ans. (d) Restricting accessibility of class members.
Explanation :
The access specifiers can be used to limit the accessibility of class members to other classes, packages etc.
2. Find the odd one.
(a) Private (b) Public (c) Protected (d) Static
Ans. (d) Static
Explanation :
Static is not an access specifier. All others are access specifiers.

3. Given the code :


class myclass{

int x=10;
public void main(){

int x=20;
x=x%3 + x%7;
system.out.println(x+"");}
}

What will be the output of the code?


(a) 8 (b) 4 (c) 5 (d)
Ans. (a) 8
Explanation :
Here, the local variable 'x' will get more priority and expression x=x%3 + x%7 will be calculated using
x=20. x=20%3 + 20%7=2+6=8.
4. Read the following text, and choose the correct answer:
A class encapsulate Data Members that contains the information necessary to represent the class and
Member methods that perform operations on the data member.
What does a class encapsulate?
(a) Info rmatio n an d operat ion (c) Data members and information
(b) Data members and Member methods (d) Member methods and operation
Ans. (b) Data members and Member methods

5. Which among the following can restrict class members to get inherited?
(a) Private (b) Protected (c) Public (d) All three
Ans. (a) Private
Explanation :
Private members of a class can't be inherited. These members can only be accessible from members of its own
class only. It is used to secure the data.
6. Which specifier allows a programmer to make the private members to be inherited?
(a) Pri vate (c) Protected
(b) D e f a u l t (d) Protected and default
Ans. (c) Protected
Explanation :

Protected access is used to make the members private. But those members can be inherited. This give' both
security and code reuse capability to a program.
7. If a class has all the private members, which specifier will be used for its implicit constructor? (a)
Private (b) Public (c) Protected (d) Default
Ans. (b) Public
Explanation
The implicit constructor should always be publics otherwise the class wouldn't be able to have instance"-In
turn, no objects will be created and the class can only be used for inheritance.

8. ____ is a method of a class which can access only static data members.
(a) instance (b) Static method (c) Class method (d) Both (b) and (c)
Ans. (d) Both (b) and (c)
Explanation :
A static method is also called a class method and it can access only the static data members of a class.
9.If a data member is declared outside all functions of a class, it is accessible to __
(a) All functions of the class (c) All functions of all classes
(b) All functions of the package (d) To the entire library
Ans. (c) All functions of all classes
Explanation :
Data members declared outside all functions of a class are accessible to all functions of the class.
10. Assertion (A): The members of a class declared without any access specifier are accessible in all classes of the
package.
Reason (R): The members without any access specifier are default or package members, hence they are
accessible in all classes of the package.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A).
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.
Ans. (a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
Explanation :
The members without any access specifier are default or package members and hence they are accessible in all
classes of the same package
Chapter
Arrays

Multiple Choice Questions


1, Java statement to access the 5th element of an array is:
(a) X[4] (b) X[5] (c) X[3] (d) X[0]
Ans. (a) X[4]
Explanation :
Index position starts from 0, so 5th element will be at index position 4.
2. The size of an array is:
(a) Fixed (c) Fixed for integer arrays only
(b) Can be changed after creation (d) None of these
Ans. (a) Fixed
Explanation :
The size of an array cannot be changed after its declaration.
3. An array index in Java starts from :
(a) 1 (b) 0 (c) 1 (d) - 99
Ans. (b) 0
Explanation :
■.•1■101.14.11

The first element of an array is assigned by index zero.

4. Arrays are :
(a) Non-mutable (c) Mutable at the first and last indexes
( b ) Mutable only if they carry Strings (d) Mutable at any index
Ans. (d) Mutable at any index
Explanation :
Arrays are mutable data structures hence they are modifiable.
5. Arrays can be called as :
( a) P ri m it i ve dat a t yp es (c) Reference data types
( b) N a t i v e d at a t y p e s (d) All of these
Ans. (c) Reference data types
Explanation :
Arrays are reference data types in Java.
6.Given an integer array of size 5, the last index will be:
(a) Oth index (b) 2 nd index (c) 4th index (d) 5th i n d ex
Ans. (c) 4th index
Explanation :
The index starts from 0 so the last index comes at 4.
7.In Java arrays are :
(a) Objects (b) Primitive types (c) References (d) Pointers
Ans. (a) Objects
8. Assertion (A): The memory occupied by an array of size n storing integers will be n x 4.
Reason (R): There are n elements in the array and an integer in Java occupies 4 bytes.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion

(c) Assertion (A) is true and Reason (R) is false.


(d) Assertion (A) is false and Reason (R) is true.
Ans. (a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
Explanation :
Since the array contains n elements and each element occupies 4 bytes, the total memory occupied
will be n x 4.

Chapter
String handling

Multiple Choice Questions


1. The output of "Remarkable".substring(6) is:
(a) mark (b) emark (c) marka (d) able
Ans. (d) able
Explanation :
Substring(6) will extract characters starting from index position 6 to the end of the string.
2. The method compareTo() returns ____________ when two strings are equal and in lowercase :
(a) true (b) 0 (c) 1 (d) false
Ans. (b) 0

Explanation:
CompareTo() method compares two strings and returns the ASCII difference of the first two dissimilar
characters in the two strings.
3. String is a:
(a) Wrapper Class (c) Group of characters
(b) Da ta Type (d) All of these
Ans. (d) All of these
Explanation : ea.

A string is a composite data type made up of multiple characters. It also represents a class modelling the
String data type with its own functions.
4. A String is a/an:
(a ) C om p osi t e dat a t yp e (c) Array
(b ) P r i m it i ve da ta t y pe (d) None of these
Ans. (a) Composite data type
Explanation :
A string is a composite data type composed of multiple characters.

5.Given the code :


class Stringclass{

public static void main(String args[]){

String obj = "circus";


String obj1 = "Atmosphere";
String obj2 = "circus";
System.out.println(obj.equals(objl) + "@" + obj.equals(obj2));}}

What will be the output of the code?


(a) False@False (b) False@True (c) True@False (d) True@True
Ans. (b) False@True
Explanation :
obj and obj1 carry different string hence equals() returns False , whereas obj and obj2 carry same string hence
equals() returns True.
6.Gi ven the code :
public class Flowers{

public static void main(String[] args)


{
String s="Flowersarebeautiful";
System.out.println(s.length()+s.lastIndexOf('u'));}}

What will be the output of the code?


(a) 35 (b) 34 (c) 36 (d) 37
Ans. (c) 36

Explanation •
s.length() returns the length of the string that is 19 and s.lastlndexOf('u') returns the index of last occurrence of
'u' that is 17 , sum of the two gives 36.

7. The output of the code will be :


public class mystring{

public static void main(String[] args){

String s = new String("FIT515");


System.out.println( s.length() + 10+ Integer.parseInt(s.substring(3))); }}

(a) 521 (b ) 5 39 (c) 530 (d) 5 31


Ans. (d) 531
Explanation :

s.length() gives the length of the string =6 + 10+ Integer.parselnt(s.substring(3)) returns "515" converted to
integer =515= 531

8.The output of the method "DETERMINATION".substring(2, 6) is:


(a) "TERM" (b) term (c) "Term" (d) "TERMI"
Ans. (a) "TERM"
9.The output of the statement "CONCENTRATION".indexOf('T') is:
(a) 9 (b) 7 (c) 6 (d) (-1)
Ans. (c) 6
Explanation :
The index position of 'T' in "CONCENTRATION" is 6

10.The output of the statement "talent".compareTo("genius") is:


(a) 11 (b) —11 (c) 0 (d) 13
Ans. (d) 13
Explanation
ASCII value of it' —ASCII value of igi =116 - 103 =13

You might also like