0% found this document useful (0 votes)
38 views

MCQ JAVA

Uploaded by

Prashant Tidke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

MCQ JAVA

Uploaded by

Prashant Tidke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTER MCQ­2021 1

Chapter 1 and 2

1. Name the programming technique that implements programs as an organised collection of interactive
objects.
a. Procedure Oriented Programming b. Modular Programming
c. Object Oriented Programming d. None of these
Ans. c. Object Oriented Programming
2. Name the characteristics of Object Oriented Programming that hides the complexity and provides a
simple interface.
a. Encapsulation b. Polymorphism
c. Abstraction d. Inheritance
Ans. c. Abstraction
3. Which among the following operator is used to access individual members of an object?
a. . (dot) b. + (plus)
c. – (minus) d. / (divide)
Ans. a. . (dot)
4. Which among the following modifier is used in a ‘class’?
a. public b. default
c. Both a and b d. None of these
Ans. c. Both a and b
5. Which among the following is a valid class name?
a. Simple Interest b. SimpleInterest
c. 1SimpleInterest d. Simple@Interest
Ans. b. SimpleInterest
6. Which among the following is a valid object name?
a. obj1 b. 1obj
c. Obj 1 d. Obj#1
Ans. a. obj1
7. Which among the following is a valid float literal?
a. 12.36f b. 12.36F
c. 12.36 d. Both a and b
Ans. d. Both a and b
8. Which among the following is a valid octal integer literal?
a. o178 b. 675
c. 0675 d. 0X675
Ans. c. 0675
9. 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
Ans. a. boolean f=true;
10. Which among the following is not a punctuator?
a. ; semicolon b. , comma
c. : colon d. . dot
Ans. d. . dot
11. Which among the following is not a primitive data type?
a. int b. float
c. String d. char
Ans. c. String
12. What is the largest possible value that can be stored in short data type?
a. 215 b. 231
c. 27 d. 263
Ans. a. 215
COMPUTER MCQ­2021 2
13. 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
Ans. b. float
14. Which among the following is not a valid error in Java?
a. Syntax errors b. Logical errors
c. Run­time errors d. Technical errors
Ans. d. Technical errors
15. Which among the following Scanner methods allows us to input a number with a decimal point?
a. nextInt() b. nextFloat()
c. nextDecimal() d. nextPoint()
Ans. b. nextFloat()
16. The output in BlueJ occurs in which window?
a. Console window b. Terminal window
c. Both a and b d. None of these
Ans. b. Terminal window
17. The input in BlueJ occurs in which window?
a. Console window b. Terminal window
c. Both a and b d. None of these
Ans. b. Terminal window
18. Assigning value to a variable during declaration is called.
a. Declaration b. Assignment
c. Initialisation d. None of these
Ans. c. Initialisation
19. Which among the following is used to represent single­line comment?
a. // b. /*
c. \\ d. <!—
Ans. a. //
20. 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.
Ans. d. Addition is required but subtraction is performed.
21. 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. Trying to store a value which is incompatible to a certain data­type. d. Missing semicolon
Ans. d. Missing semicolon
22. 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
Ans. a. Initialisation
23. 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. Parameterised input b. Initialisation
c. Scanner input d. None of these
Ans. c. Scanner input
24. Which among the following is not a primitive data type?
a. int b. short
c. String d. long
Ans. c. String
25. Name the operator that is used to allocate memory space for an object.
a. Dot b. new
c. Both a and b d. None of these
COMPUTER MCQ­2021 3
Ans. b. new
26. What is the name given to a memory location called in Java?
a. Variable b. Constant
c. Data Type d. None of these
Ans. a. Variable
27. Which are the data types used in Java?
a. Primitive data type b. Composite data type
c. Both a and b d. None of these
Ans. c. Both a and b
28. How are the characteristics of an object represented in a class?
a. Data Members b. Member Functions
c. Access specifiers d. None of these
Ans. a. Data Members
29. Which among the following is used to change the state of an object?
a. Data Members b. Name of the class
c. Both a and b d. None of these
Ans. a. Data Members
30. How is encapsulation implemented in a program?
a. Using a class b. Using only Functions
c. Using only Variables d. None of these
Ans. a. Using a class
31. Information passed to a method through arguments is called _____________.
a. Message b. Variables
c. Numbers d. Data
Ans. a. Message
32. What among the following is not a component of a message?
a. An object identifier b. A method name
c. Arguments d. Data Members
Ans. d. Data Members
33. How many objects can you create from a class?
a. One b. Two
c. Three d. Any number
Ans. d. Any number
34. Unary operator requires ___ operand(s) to operate on.
a. 1 b. 2
c. 3 d. none of them
Ans­ a
35. Choose the value of y after evaluating the given expression:
y+=++y+y­­+­­y; when y=8.
a. 33 b. 24
c. 31 d. 20
Ans: a
36. Identify the name of '&&' operator:
a. Increment operator b. Logical operator
c. Ternary operator d. Relational operator
Ans: b
37. What is the function of the % operator?
a. divides one operand with another b. used to find percentage
c. gives the remainder of division d. none of the above
Ans: c
38. Choose the output of :
char res= 'F';
COMPUTER MCQ­2021 4
int n= res;
n=n+5;
System.out.println(n+" "+res);
a. 25F b. 75 70
c. 75 F d. 145
Ans: c
39. What is the ASCII value of A?
a. 65 b. 64
c. 62 d. 97
Ans: a
40. Select the appropriate Java expression for ut+1/2at
a. u*t+1/2at b. u*t+1/2*a*t
c. ut+1/2at d. none of them
Ans: b
41. Name the casting shown by
int x=(int) b;
a. implicit b. explicit
c. both of them d. none of them
Ans: b
42. Choose the correct output of the following code:
System. out.println("BEEN");
System. out.print(" VERY ILL");
a. has BEEN VERY ILL
b. BEEN
VERY ILL
c. has BEEN
VERY WELL
d. None of them
Ans: b
43. System.out.println("Jelly"); Is an example of?
a. Assignment b. Method invocation
c. Object creation d. Increment
Ans: b
44. Which one of the following is given the highest preference?
a. && b. %
c. >= d. ++
Ans: d
45. If num=500;
int num,sum,n=600;
sum= (n+num)>2000?500:600;
System.out.println(sum);
a. 600 b. 500
c. 200 d. none of these
Ans: a
46. 'Type conversion' is also called
a. Type casting b. Type change
c. Type inversion d. None of these
Ans: a
47. What is the value of a when x=5?
a=5*x++;
a. 30 b. 25
c. 55 d. 50
COMPUTER MCQ­2021 5
Ans: b
48. What is the ASCII value of b?
a. 66 b. 65
c. 98 d. 97
Ans: c
49. Choose the correct value of x, if x=3,y=7
x­=x++­++y;
a. 8 b. 6
c. ­8 d. 2
Ans: a
50. What is the value of y when a=7
y=2*++a;
a. 14 b. 16
c. 20 d. 36
Ans: b
51. Choose the attributes required for class definition :
a. keyword class b. name of the class
c. both a and b d. none of them
Ans: c

B. State whether the following statements are True (T) or False (F).
1. Encapsulation refers to the art of hiding the complexities and giving a simple interface. F
2. Procedure Oriented Language follows top down approach. T
3. Java is an example of Object Oriented Language. T
4. Hiding the complexity and giving a simple interface is called Inheritance. F
5. Abstraction is same as encapsulation. F
6. An object is called a class factory. F
7. A class is an instance of an object. F
8. A class is a mechanism to implement encapsulation. T
9. Data members in a class is used to represent the characteristic of an object. T
10. The new operator is used to create an object. T
11. It’s a rule to have a class­name beginning in capital letter. F
12. Scanner class is present in the java.lang package. F
13. Math.abs( ) is used to find the absolute value of a number. T
14. The return type of Math.sqrt( ) function is float. F
15. The fraction 1/2 will evaluate to 0.5. F
16. The continue statement in a switch block is used to avoid fall through. F
17. The default statement is essential in a switch block. F
18. The for loop is an entry controlled loop. T
19. The while loop is an exit controlled loop. F
20. The do­while loop is generally used when the number of iterations is known. F
21. You can have only the for loop as the nested loops. F

C. Fill in the blanks.


1. A class is a template that binds together data and methods together.
2. The values in the attributes of an object is called the state of an object.
3. The dot operator is used to access the individual members of a class.
4. The keyword new is used to allocate memory space for an object.
5. The default and public access modifier is used with a class.
6. An object is an identity with certain characteristic and behaviour.
7. The values/attributes of the characteristics of an object are called the state of an object.
8. All the complexities of a program should be encapsulated in such a way so that abstraction
COMPUTER MCQ­2021 6
is obtained.
9. Inheritance allows us to encompass the parent class’ state and behaviours into its child..
10. Poly­means many and Morphism means forms.
11. The break statement is used to avoid fall through.
12. The next().chart(0) function of the Scanner class is used to accept a character from the user.
13. A loop within another loop is called nested loops.
14. The relational/comparison operator is used to compare two quantities.
15. The else block is preceded by the if block.
16. The sqrt() function of the Math class is used to return the square root of a number.
17. The return type of cbrt( ) function is double.
18. The continue jump statement is used to skip the remaining statements in a loop.
19. Single line comment and multiline comments are two types of comments in Java.
20. Any error in the grammar of the language is a syntax error.

Chapter 3

1. Once a function is defined, it can be invoked repeatedly. What is this feature called?
a. Interface b. Reusability
c. Restructuring d. All of these
Ans. b. Reusability
2. If a function does not return any value, its return type should be:
a. int b. no­return
c. void d. empty
Ans. c. void
3. A function that computes a value and returned is called:
a. Computational function b. Manipulative function
c. Procedural function d. None of these
Ans. a. Computational function
4. A type of parameter that are used to identify what data is to be passed to a function is called:
a. Formal parameter b. Actual parameter
c. Both a and b d. None of these
Ans. a. Formal parameter
5. The parameter list in a function definition is called:
a. Function prototype b. Function signature
c. Both a and b d. None of these
Ans. b. Function signature
6. The first line of the function definition is called:
a. Function prototype b. Function signature
c. Both a and b d. None of these
Ans. a. Function prototype
7. The number of values that a function can return is:
a. 1 b. 2
c. 3 d. 4
Ans. a. 1
8. A local variable in a function has its scope:
a. Limited within the function b. Can be accessed anywhere within the same class
c. No limitation at all d. None of these
Ans. a. Limited within the function
9. Which among the following is a valid name for a function?
a. function b. 2function
c. fun in action d. fun#
Ans. a. function
COMPUTER MCQ­2021 7
10. Which among the following is not a valid access specifier?
a. public b. private
c. partially d. protected
Ans. c. partially

B. Fill in the blanks.


1. In Java functions are known as methods.
2. Methods are contained in class.
3. The function name and the parameter list together is known as function signature.
4. The access specifier, return type and the function signature together is known as prototype.
5. The arguments of the function given in function prototype are called formal arguments.
6. The arguments of the function given in statement that calls the function are called actual
arguments.
7. If a function does not return any value, the returning type in the function prototype will be void.
8. When a function is called by value, the values of actual parameters are copied into separate
memory locations as allocated by the formal parameters.
9. Impure functions uses call by reference.
10. One of the practical implementation of polymorphism is overloading.

Chapter 4

1. 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 initialisation.
d. It can be invoked using an object like any other member function.
Ans. d. It can be invoked using an object like any other member function.
2. If the name of a class is ‘Number’, what can be the possible name for its constructor?
a. Number b. number
c. No d. No
Ans. a. Number
3. 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
Ans. c. Both a and b
4. If constructors are overloaded, what differentiates it?
a. Parameter list b. Return type
c. Both a and b d. None of these
5. What access specifier for a constructor allows you to create an object only within the class?
a. public b. private
c. protected d. default
Ans. b. private
6. Name the type of constructor that gets invoked when an object is created, which is initialised with the
content of another object.
a. Copy constructor b. Default constructor
c. Overloaded constructor d. None of these
Ans. a. Copy constructor
7. Categorise the type of object that can be created without any name or identifier.
a. Temporary object b. Anonymous object
c. Both a and b d. None of these
Ans. c. Both a and b
COMPUTER MCQ­2021 8
8. Predict the output of the following program:
class T
{
int t = 20;
T()
{
t = 40;
}
public static void main(String args[])
{
T t1 = new T();
System.out.println(t1.t);
}
}
a. 20 b. 40
c. Compiler Error d. None of these
Ans. b. 40
9. The following code contains one compilation error, find it?
public class Test {
Test() { } // line 1
static void Test() { this(); } // line 2
public static void main(String[] args) { // line 3
Test(); // line 4
}}
a. At line 1, constructor Tester must be marked public like its class
b. At line 2, constructor call
c. At line 3, compilation error, ambiguity problem, compiler can’t determine whether a constructor
d. At line 4
Ans. b. At line 2, constructor call
10. Which of the following is not true for static block?
a. It is used to initialise static variables.
b. It gets executed when a class gets loaded in the memory.
c. It can print the content of instance variables.
d. It begins with the static keyword.
Ans. c. It can print the content of instance variables.
11. public class Test { }
What is the prototype of the default constructor?
a. public Test(void) b. Test( )
c. Test(void) d. public Test( )
Ans. b

You might also like