1.
What is the range of short data types in Java?
Correct Answer
B. -32768 to 32767
Explanation
Explanation: Short occupies 16 bits in memory. Its range is from -32768 to 32767.
2.
What is the numerical range of a char data type in Java?
Correct Answer
D. 0 to 65535
Explanation
Explanation: Char occupies 16-bit in memory, so it supports 2^16 i:e from 0 to 65535.
3.
Which of these is a long data type literal?
Correct Answer
A. 0x99fffL
Explanation
Explanation: Data type long literals are appended by an upper or lowercase L. 0x99fffL is hexadecimal long literal.
4.
Which of these operators is used to allocate memory to array variables in Java?
Correct Answer
C. New
Explanation
Operator new allocates a block of memory specified by the size of array, and gives the reference of memory allocated to the array variable.
5.
Which of these is not a bitwise operator?
Correct Answer
D.
Explanation
Explanation:
6.
What is the output of relational operators?
Correct Answer
B. Boolean
Explanation
Explanation: None
7.
Which of these have highest precedence?
Correct Answer
A. ( )
Explanation
Explanation: Order of precedence is (highest to lowest) a -> b -> c -> d.
8.
Which of these selection statements test only for equality?
Correct Answer
B. Switch
Explanation
Explanation: switch statements checks for equality between the controlling variable and its constant cases.
9.
What is the stored in the object obj in following lines of code?
box obj;
Correct Answer
B. NULL
Explanation
Explanation: Memory is allocated to an object using new operator. box obj; just declares a reference to object, no memory is allocated to it hence it points to NULL
10.
What is the return type of a method that does not returns any value?
Correct Answer
C. Void
Explanation
Explanation: void method does not return any value.
11.
What is the return type of Constructors?
Correct Answer
A. Int
Explanation
Explanation: Constructors does not have any return type, not even void.
12.
What is a process of defining two or more methods within the same class that have the same name but different parameters declaration?
Correct Answer
A. Method overloading
Explanation
Explanation: Two or more methods can have the same name as long as their parameters declaration is different, the methods are said to be overloaded and the process is called method overloading. Method overloading is a way by which Java implements polymorphism.
13.
Which of these access specifiers must be used for main() method?
Correct Answer
B. Public
Explanation
Explanation: main() method must be specified public as it called by Java run time system, outside of the program. If no access specifier is used then by default member is public within its own package & cannot be accessed by Java run time system.
14.
Arrays in Java are implemented as?
Correct Answer
B. Object
Explanation
Explanation: Array is object container which is used to hold a collection of fixed value having the same type.
15.
String in Java is a?
Correct Answer
A. Class
Explanation
Explanation: None
16.
Which of ​this keyword must be used to inherit a class?
Correct Answer
D. Extends
Explanation
The keyword "extends" must be used to inherit a class. Inheritance is a mechanism in object-oriented programming that allows a class to inherit the properties and methods of another class. By using the "extends" keyword, a subclass can inherit the attributes and behaviors of a superclass, enabling code reuse and promoting a hierarchical structure in the program.
17.
Which of these keywords can be used in subclass to call the constructor of superclass?
Correct Answer
A. Super
Explanation
The keyword "super" can be used in a subclass to call the constructor of the superclass. It is used to invoke the superclass constructor and initialize the inherited members of the subclass. This allows the subclass to inherit and utilize the functionality of the superclass while also adding its own unique features.
18.
Which of these class is superclass of every class in Java?
Correct Answer
B. Object class
Explanation
Explanation: Object class is a superclass of every class in java
19.
Which of these class is superclass of String and StringBuffer class?
Correct Answer
B. Java.lang
Explanation
The correct answer is "java.lang" because the java.lang package contains fundamental classes and interfaces that are essential to the Java programming language. String and StringBuffer classes are both part of this package, making it the superclass of both.
20.
Which of these method of class String is used to extract more than one character at a time a String object?
Correct Answer
D. GetChars()
Explanation
The method getChars() is used to extract more than one character at a time from a String object.
21.
Which of these method of class String is used to compare two String objects for their equality?
Correct Answer
A. Equals()
Explanation
The method "equals()" is used to compare two String objects for their equality. This method checks if the content of the two strings is the same, regardless of their memory location. It returns a boolean value, true if the strings are equal, and false if they are not.
22.
Which of these method of class String is used to extract a substring from a String object?
Correct Answer
A. Substring()
Explanation
The correct answer is substring(). This method is used to extract a substring from a String object. It takes two parameters, the starting index and the ending index, and returns a new string that is a subset of the original string. The substring() method is case-sensitive and the ending index is exclusive, meaning it does not include the character at that index in the substring.
23.
Which of these class is used to create an object whose character sequence is mutable?
Correct Answer
B. StringBuffer()
Explanation
Explanation: StringBuffer represents growable and writeable character sequence.
24.
Which of these keywords is used to define packages in Java?
Correct Answer
C. Package
Explanation
The keyword "package" is used to define packages in Java. Packages are used to organize classes and interfaces into groups, making it easier to manage and maintain large codebases. By using the "package" keyword followed by the package name, developers can create a hierarchical structure for their code. This allows for better organization, reusability, and encapsulation of code.
25.
Which of these keywords is used to define interfaces in Java?
Correct Answer
A. Interface
Explanation
The keyword "interface" is used to define interfaces in Java. In Java, an interface is a collection of abstract methods that can be implemented by a class. It defines a contract that a class must adhere to if it wants to implement that interface. The other options "Interface", "intf", and "Intf" are not valid keywords in Java for defining interfaces.
26.
Which of these classes is not included in java.lang?
Correct Answer
C. Array
Explanation
Explanation: Array class is a member of a java.util
27.
Which of these class have only one field ‘TYPE’?
Correct Answer
A. Void
Explanation
Explanation: The Void class has one field, TYPE, which holds a reference to the Class object for the type void.
28.
Which of these class is superclass of all other classes?
Correct Answer
D. Object
Explanation
The correct answer is "Object" because in Java, the Object class is the root class for all other classes. It is at the top of the class hierarchy and serves as the superclass for all other classes. Every class in Java directly or indirectly extends the Object class, which provides basic functionalities and methods that are inherited by all other classes.
29.
Which of these class is used for input and output operation when working with bytes?
Correct Answer
A. InputStream
Explanation
Explanation: InputStream & OutputStream are designed for byte stream. Reader and writer are designed for character stream.
30.
Which of these is a process of writing the state of an object to a byte stream?
Correct Answer
A. Serialization
Explanation
Serialization is the process of writing the state of an object to a byte stream. This is used when you want to save the state of your program to the persistent storage area.