Set2 MCQ Answers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Grade IX Syllabus

Introduction to OOP
Choose the correct answer.
1. An object is represented by two attributes, out of which one is characteristics and the other one is
___________.
a. Behaviour b. Situation
c. Abstraction d. Encapsulation
2. Name the programming technique that implements programs as an organized collection of interactive
objects.
a. Procedure Oriented Programming b. Modular Programming
c. Object Oriented Programming d. None of these
3. Name the programming technique that specifies a series of well-structured steps and procedures within
its programming context to compose a program.
a. Procedure Oriented Programming b. Modular Programming
c. Object Oriented Programming d. None of these
4. Name the characteristics of Object Oriented Programming that hides the complexity and provides a
simple interface.
a. Encapsulation b. Polymorphism
c. Abstraction d. Inheritance
5. What is the behaviour aspect of an object represented by?
a. Member Functions b. Data Members
c. Both a and b d. None of these
6. What is the ability of an object to take on many forms called?
a. Polymorphism b. Encapsulation
c. Abstraction d. Inheritance
7. Name the art of implementing Encapsulation in Object Oriented Programming.
a. Polymorphism b. Encapsulation
c. Abstraction d. class
State true or false
1. Encapsulation refers to the art of hiding the complexities and giving a simple interface. False
2. Procedure Oriented Language follows top down approach. True
3. Java is an example of Object Oriented Language. True
4. Abstraction is same as Encapsulation. False
Fill in the blanks
1. All the complexities of a program should be encapsulated in such a way so that _______ is obtained.
a. Abstraction b. Encapsulation
c. Polymorphism d. Inheritance
2. Polymorphism means _____________.
a. one form b. multiple forms
c. two forms d. None of these
3. It is a principle of Object Oriented Programming (OOP) that binds together characteristics and
behaviour of an object.
a. Polymorphism b. Inheritance
c. Abstraction d. Encapsulation
4. A program written in a high level language is also called ___________.
a. Source code b. Byte code
c. Object code d. None of these
5. All ___________ have identity and are distinguishable even if the constituent components are same.
a. class b. object
c. method d. data

Introduction to Java
Choose the correct answer.
1. What is Java Programming Language?
a. A runtime system b. A set of development tools.
c. An Application Programming Interface (API) d. All of these
2. Name the process that converts source code to bytecode.
a. Interpretation b. Compilation
c. All of these d. None of these
3. A Virtual Processor that is implemented in software and runs using the capabilities provided by your
operating system and computer hardware.
a. Byte Code b. Compiler
c. Interpreter d. Java Virtual Machine(JVM)
4. Which among the following is not a language feature in Java?
a. Robust b. Secured
c. Platform Independent d. Procedure Oriented
5. Name the programs that can be developed in such a way that it remains embedded in a web page and
runs on the viewer’s machine in a secured manner by Java compatible browsers.
a. Applets b. Applications
c. Both a and b d. None of these
6. Name the program that is written and compiled which may then be executed in any machine provided it
contains the JVM.
a. Applets b. Applications
c. Both a and b d. None of these
7. What is a set of pseudo machine language instructions that are understood by the Java Virtual Machine
and are independent of the underlying hardware called?
a. JVM b. Source Code
c. Compilation d. Bytecode
State whether the following statements are True (T) or False (F).
1. The byte code when compiled gives source code. False
2. A Java program can execute only in Windows machine. False
3. Source Code in Java has the .class extension. False
4. Java is simple to learn. True
Elementary concept of objects and classes
1. Which among the following creates a blueprint to represent characteristic and behaviour of an object?
a. Object b. Class
c. Instance d. None of these
2. Which among the following is not a component of a class?
a. Modifiers b. Class name
c. Object d. Body
3. Which among the following keyword is used to allocate memory space for an object?
a. new b. for
c. while d. int
4. Which among the following operator is used to access individual members of an object?
a. . (dot) b. + (plus)
c. – (minus) d. / (divide)
5. Which among the following is a valid class name?
a. Simple Interest b. SimpleInterest
c. 1SimpleInterest d. Simple@Interest
6. Which among the following is a valid object name?
a. obj1 b. 1obj
c. Obj 1 d. Obj#1
7. If a method named show( ) is to be invoked using an object ‘ob’ , which among the following is correct?
a. ob.show( ) b. ob.show
c. show( ).ob d. None of these
State whether the following statements are True (T) or False (F).
1. An object is called a class factory. False
2. A class is an instance of an object. False
3. A class is a mechanism to implement encapsulation. True
4. Data members in a class are used to represent the characteristic of an object. True
5. The new operator is used to create an object. True
6. It’s a rule to have a class-name beginning in capital letter. False
7. Java is case sensitive. True
8. A class-name cannot be a keyword. True
9. In programming every object will have a name. True
Values and Data types
Choose the correct option.
1. Which among the following encoding system can represent 65536 characters?
a. ASCII b. Unicode
c. Both a and b d. None of these
2. Which among the following is not a Token?
a. Keywords b. Literals
c. Identifiers d. Data Type
3. Which among the following is a keyword but not a literal?
a. for b. null
c. true d. false
4. Which among the following is a valid float literal?
a. 12.36f b. 12.36F
c. 12.36 d. Both a and b
5. Which among the following is a valid method of initialising?
a. boolean f=true; b. boolean f=True;
c. boolean f=’true’; d. None of these

6. Which among the following is not a punctuator?


a. ; semicolon b. , comma
c. : colon d. . dot
7. Which among the following is not a primitive data type?
a. int b. float
c. String d. char
8. If a is of type int and b is of type float what would be the resultant data type of a+b?
a. int b. float
c. double d. short
9. A floating point number consists of
a. integral part only b. fractional part
c. both integral and fractional part d. None of these
Operators in Java
Choose the correct option.
1. Which among the following is a relational operator?
a. + b. > c. * d. /
2. The && operator requires which among the following conditions to be satisfied to represent a success
for two relations?
a. Both should be satisfied b. Any one should be satisfied.
c. None of them are satisfied. d. None of these
3. Which among the following is not a logical operator?
a. && b. || c. ! d. <=
4. Which among the following is the correct construct for creating an object named ‘book’ of the class
‘Library’?
a. Library book=new Library; b. book =new Library();
c. Library() book=new Library(); d. Library book=new Library();
5. What will be the result of the statement a%2 , if the value of ‘a’ is an even number?
a. 0 b. 1 c. Both a and b d. None of
these
6. Which among the following operators is used to check the two operands are equal or not?
a. Equals b. = c. == d. None of these
7. Which among the following forms of operators works with three operands?
a. Unary b. Binary c. Ternary d. None of these
8. If a=2, b=5 then what will be the value of x in the following statement?
x=(a>b)?a:b;
a. 2 b. 5 c. 7 d. None of these
9. What will be the value of 110%13?
a. 3 b. 5 c. 6 d. 9
Input in Java
Choose the correct option.
1. Which among the following is not valid error in Java?
a. Syntax errors b. Logical errors
c. Run-time errors d. Technical errors
2. Which among the following Scanner methods allows us to input a number with a decimal point?
a. nextInt() b. nextFloat()
c. nextDecimal() d. nextPoint()
3. The output in BlueJ occurs in __________ window.
a. Console window b. Terminal window
c. Both a and b d. None of these
4. Assigning value to a variable during declaration is called _________
a. Declaration b. Assignment
c. Initialisation d. None of these
5. Which among the following is used to represent single-line comment?
a. // b. /* c. \\ d. <!—
6. Which among the following is a logical error?
a. Missing semicolon b. Mismatched braces in classes and
methods.
c. Misspelled keywords and identifiers. d. Addition is required but subtraction is
performed.
7. Which among the following represents a syntax error?
a. Dividing an integer by zero.
b. Accessing an element that is out of bounds of an array.
c. Finding the square root of a negative number.
d. Missing semicolon
8. Which are the errors, in spite of which the program compile and run?
a. Logical errors b. Syntax errors
c. Run time errors d. None of these
9. Comments can be written
a. in the beginning of the program b. at the end of the program
c. anywhere in the program d. None of these
10. If the data that is to take part in a calculation in a method is fixed, which form of input is necessary?
a. Initialisation b. Parameterised input
c. Scanner input d. None of these
11. In case you need to give a proper message (prompt string) before taking an input from the user, which
would be the most preferable method?
a. Initialisation b. Parameterised input
c. Scanner input d. None of these
Mathematical Library methods
Choose the correct answer.
1. Which among the following package is imported by default?
a. java.lang b. java.util
c. Both a and b d. None of these
2. Which among the following class do not belong to the java.lang package?
a. System b. String
c. Math d. Scanner

3. Which among the following function returns the absolute value of a number?
a. Math.absoulute( ) b. Math.neutral( )
c. Math.abs( ) d. Math.positive( )
4. Which among the following gives the next mathematical integer?
a. Math.floor( ) b. Math.ceil( )
c. Math.random( ) d. All of these
5. What is the return type of Math.min(1,2.0f)?
a. float b. double
c. int d. long
6. Which among the following function is equivalent to Math.sqrt(a)?
a. Math.cbrt(a); b. Math.pow(a,1/2)
c. Math.pow(a,1/2.0); d. Math.
7. What value will Math.sqrt(-9) return?
a. -3.0 b. 3.0
c. NaN d. None of these
8. What value will Math.sqrt(Math.ceil(8.1)) return?
a. 9.0 b. 9
c. 3.0 d. 4.0
State whether the following statements are True (T) or False (F).
1. It is possible to find the square root of a number using the Math.pow() function. T
2. Math.sqrt() function is used to find the square of a number. F
3. Math.abs() function is used to round off a real number to the nearest integer. F
4. Math. rint(12.5) will return 12.0. T
5. Math.ceil() and Math.floor() are same. F
6. NaN stands for Not a Number, which is received when you pass a negative number to the Math.sqrt()
function. T
7. Math.round() function returns an int value if the parameter is float data type and long value if the
parameter is of double data type. T
8. You cannot find the cube root of a number in Java. F
9. Math.random( ) returns a random number between 0 and 1 in decimal. T
10. Math.max( ) returns the number having maximum number of digits. F
Give the output of the following expressions.
i. If x = -9.99, calculate Math.abs(x);
ii. If x = 9.0, calculate Math.sqrt(x);
B. Give the output of the following functions:
1. Math.floor(-126.349)
2. Math.max(45.6,17.3)
3. Math.min(-0.0,0.0)
4. Math.pow(4,3)
5. Math.sqrt(625)
6. Math.cbrt(125)
7. Math.max(11,11)
8. Math.ceil(-12.56)
9. Math.floor(15.36)
10. Math.round(146.5)
Conditional constructs in Java
Choose the correct option.
1. If a relational expression is satisfied it results in ______________.
a. true b. false
c. Both a nd b d. None of these
2. Which among the following logical operator is used to negate a condition?
a. && b. ||
c. ! d. All of these
3. An if statement inside another if statement is called _____________.
a. Nested if b. Internal if
c. Concentric if d. None of these
4. Which of these selection statements test only for equality?
a. if b. switch
c. if and switch d. none of the mentioned
5. The conditional statement ________ can only test for equality, whereas ______can evaluate any type of
Boolean expression.
a. if, switch b. switch, if
c. while, if d. if, while
6. What will be the output of the following code snippet?
int a=15;
int b=25;
if ((a<b) || (a=5)>15)
System.out.println(a);
else
System.out.println(b);
a. Error b. 15
c. 25 d. No output
State true or false for the following.
1. Switch statement does not involve True or False. True
2. Semicolon is allowed with switch construct. False
3. while, for, if, else are keywords in Java. True
4. compound statement in enclosed between a pair of braces ( ). False
5. A comma operator is used for dual purpose. It can be used to form a compound statement and also as a
separator. True
Iterative constructs in Java
Choose the correct option.
1. A type of loop that is usually used when the number of iteration is known.
a. for b. while
c. do-while d. None of these
2. By using this, you can force immediate termination of loop, bypassing the conditional expression and
any remaining code in the body of the loop.
a. switch b. break
c. continue d. default
3. In while loops, a statement causes control to be transferred directly to the conditional expression that
controls the loop.
a. break b. pause
c. start d. continue
4. What is an infinite loop?
a. A loop that functions infinitely well b. A loop that runs forever
c. A loop that never starts d. A loop that will never function
5. What is the value of k after the following code fragment?
int k = 0;
int n = 12
while (k < n)
{
k = k + 1;
}
a. 0 b. 11 c. 12 d. Unknown
6. What’s wrong? for (int k = 2, k <= 12, k++)
a. the increment should always be ++k
b. the variable must always be the letter i when using a for loop
c. there should be a semicolon at the end of the statement
d. the commas should be semicolons
7. What’s wrong? while( (i < 10) && (i > 24))
a. the logical operator && cannot be used in a test condition
b. the while loop is an exit-condition loop
c. the test condition is always false
d. the test condition is always true
Choose the correct answer
1. Which operator cannot be used with if-else statement?
a. <= b. ||
c. && d. ? :
2. Predict the output of the following code snippet:
int a = 1;
int b = 2;
if (a == b)
System.out.println ("Both values are equal");
else
System.out.println ("Values are not equal");
a. Both values are equal b. Incorrect use of the == operator
c. Values are not equal d. No output
3. Consider the following code snippet:
if ( c > d)
x = c;
else
x = d;
Choose the correct option if the code mentioned above is rewritten using the ternary operator:
a. x = (c >d) ? c : d; b. x = (c >d) ? d : c;

c. x = (c >d) ? c : c; d. x = (c >d) ? d : d;
4. if ((a > b) && (a > c)), then which of the following statements is true?
a. a is the largest number. b. b is the largest number.
c. c is the largest number. d. b is the smallest number.
5. Consider the following code snippet:
int val = 2;
switch (val)
{
case 1: System.out.println("Case 1");
break;
case 2: System.out.println("Case 2");
break;
default: System.out.println("No match found");
break;
}
Which of the following statements is correct?
a. case 1 will be executed. b. case 2 will be executed.
c. default will be executed. d. both case 1 and 2 will be executed.
6. A sequence of statements enclosed between a pair of curly brackets is called _____________
a. a compound statement b. an empty statement
b. a null statement d. a void statement
7. If a, b and c are the sides of a triangle then which of the following statement is true for: if(a!=b && a!=c
&& b!=c)?
a. Equilateral triangle b. Scalene triangle
c. Isosceles triangle d. All of the above
8. Which of the following is a conditional statement?
a. if b. goto
c. for d. None
9. A Java program executes but doesn’t give the required output. It is due to:
a. the logical error in the program b. the syntax error in the program
c. the runtime error in the program d. none
10. Which of the following is not applicable for a constructor function?
a. It has the same name as the class.
b. It has no return-type
c. It is usually used for initialization.
d. It can be invoked using an object like any other member function.
User defined methods
1. Different variables used in the list of parameters are separated by ________
a. . (dot) b. , (comma)
c. ; (semicolon) d. : (colon)
2. Which of the following is the correct prototype for a function proto that takes two integer values and
return a boolen?
a. void proto(int a,int y) b. int proto(a, b)
c. boolean proto(int a, int y) d. int proto(int a, int b)
3. What is the access specifier for the function int recall(int x, int y)?
a. private b. protected
c. public d. None
4. Which character is used to import all classes and functions of a package?
a. / b. &
c. * d. ^
Answer true or false.
1. Objects are passed to a method by the use of call by reference. True
2. A method can be declared as static. True
3. A method declared static cannot access not-static class members. True
Constructors
1. If the name of a class is ‘Number’, what can be the possible name for its constructor?
a. Number b. number
c. Num d. No
2. Which among the following is a type of constructor?
a. Parameterised constructor b. Non-parameterised constructor
c. Both a and b d. None of these
3. If constructors are overloaded, what differentiates it?
a. Parameter list b. Return type
c. Both a and b d. None of these
4. What access specifier for a constructor allows you to create an object only within the class?
a. public b. private
c. protected d. default

Name the following:

1. Keyword that distinguishes between instance and class variables - static


2. Package that contains Scanner class – java.util
3. Escape sequence used as a new line character - \n
4. A set of valid characters that a language can recognize – Character set
5. Word carrying special meaning and purpose for the compiler - Keyword
6. User defined names for the different parts of the program - Identifiers
7. Data items that never change their value during a program run - Literals
8. Smallest individual unit in a program - Tokens
9. Variables that are shared by all the objects – class variables
10. Symbolic name for a computer memory location - Variable
11. Symbols that trigger some operations
12. Character set used in Java - Unicode
13. Keyword used to call a package - import
14. Default initial value of a boolean data type - false
15. Return type of the function random( ) - double
16. 64 bit integer data type - long
17. 16 bit Unicode character - char
18. Bytes occupied by float data type - 4
19. The process by which one object acquires the properties of another object - Inheritance
20. Another name for member variables – data members
21. The unit of the class gets called, when the object of the class is created - constructor
22. Other name for conditional operator – Ternary operator
23. Parameters appearing in function definition - Formal
24. A package that is invoked by default. – java.lang
25. The function in which the data in actual parameters get changed – Call by reference
26. Many functions with the same name – Method Overloading
27. The function in which the data in actual parameters remain intact – Call by value
28. Keyword that indicates a method has no return type - void
29. Keyword that causes the control to transfer back to the method call - return
30. Name the operators

< ++ && ?: +

Relational Unary Logical Ternary Arithmetic

31. Constructors that take arguments – Parameterized constructors


32. Two or more constructors defined in a class – Constructor Overloading
33. Clause optional in switch case - default

You might also like