Java MCQ Questions and answers. Important basic to advance MCQs for freshers interview placement and Competitive Exam’s preparation with PDF Download. Helpful for TCS, Wipro, COPA, Virtusa, DCA, Wings, infytq and other exam.
1. Number of primitive data types in Java are?
2. What is the size of float and double in Java?
3. Automatic type conversion is possible in which of the possible cases?
4. Find the output of the following code.
int Integer = 24;
a) Compile error
b) Throws exception
5. Select the valid statement.
a) char[] ch = new char(5)
b) char[] ch = new char[5]
c) char[] ch = new char()
d) char[] ch = new char[]
6. When an array is passed to a method, what does the method receive?
a) The reference of the array
b) A copy of the array
c) Length of the array
d) Copy of the first element
7. Select the valid statement to declare and initialize an array.
8. Arrays in java are-
a) Object references
c) Primitive data type
9. When is the object created with new keyword?
b) At compile time
c) Depends on the code
10. Identify the correct definition of a package.
a) A package is a collection of editing tools
b) A package is a collection of classes
c) A package is a collection of classes and interfaces
d) A package is a collection of interfaces
11. Identify the correct restriction on static methods.
i) They must access only static data
ii) They can only call other static methods
iii) They cannot refer to this or super
12. Identify the keyword among the following that makes a variable belong to a class, rather than being defined for each instance of the class.
13. In which of the following is toString() method defined?
14. CompareTo() returns
15. Identify the output of the following program.
String str = “Hellow”;
Ans. d (Since, t isn’t present in the string str, it returns -1.)
16. To which of the following does the class string belong to.
17. How many objects will be created in the following?
String a = new String(“heetson”);
String b = new String(“heetson”);
Strinc c = “heetson”;
String d = “heetson”;
Explanation: Using the new keyword creates an object everytime. Hence, 2 objects are created for first two statement. Next, a string is declared which creates another object. For the fourth statement, since, a string ”heetson” already exists, it doesn’t create an additional object again. Hence, answer is 3.
18. Total constructor string class have?
19. Find the output of the following code.
b) Compile error as ++a is not valid identifier
20. Identify the return type of a method that does not return any value.
21. Output of Math.floor(3.6) is
Ans. b (floor returns largest integer that is less than or equal to the given number.)
22. Where does the system stores parameters and local variables whenever a method is invoked?
23. Identify the modifier which cannot be used for constructor.
24. What is the variable declared in a class for the use of all methods of the class called?
b) Instance variables
c) Reference variable
25. What is the implicit return type of constructor?
b) A class object in which it is defined
26. When is the finalize() method called?
a) Before garbage collection
b) Before an object goes out of scope
c) Before a variable goes out of scope
27. Identify the prototype of the default constructor.
Public class Solution <>
c) public Solution(void)
d) public Solution()
28. Identify the correct way of declaring constructor.
Public class Solution <>
b) public Solution()<>
29. Identify the infinite loop.
d) All of the above
30. What is Runnable?
a) Abstract class
31. Exception created by try block is caught in which block
32. Which of the following exception is thrown when divided by zero statement is executed?
33. Where is System class defined?
34. Identify the interface which is used to declare core methods in java?
35. Which of the following statement are true about finalize() method?
a) It can be called Zero or one times
b) It can be called Zero or more times
c) It can be called Exactly once
d) It can be called one or more times
36. What does the operator >>>> do?
a) Right shift operator
b) Left shift operator
c) Zero fill left shift
d) Zero fill right sift
37. Identify the incorrect java feature.
a) Object oriented
b) Use of pointers
d) Architectural neural
38. Which environment variable is used to set the java path?
39. Which of the following is not an OOPS concept in Java?
40. What is not the use of “this” keyword in Java?
a) Referring to the instance variable when a local variable has the same name
b) Passing itself to the method of the same class
c) Passing itself to another method
d) Calling another constructor in constructor chaining