Class 10 MCQ
Class 10 MCQ
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
for(i = 0;i<5;i++)
System.out.println("hello"); break;
Animal Class I
L
Multiple Choice Questions
1.
r:t
Chapter
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.
Chapter
Constructors
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.
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
int x=10;
public void main(){
int x=20;
x=x%3 + x%7;
system.out.println(x+"");}
}
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
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
Chapter
String handling
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.
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.
s.length() gives the length of the string =6 + 10+ Integer.parselnt(s.substring(3)) returns "515" converted to
integer =515= 531