Java Quiz 1

By | February 17, 2018

This quiz contains basic Java questions to start with. Giving the quiz helps in brushing up Java concepts and its fun as well to analyze yourself before appearing for any real time test.

Java Quiz 1

Question 1
'this' keyword is used to:
A
refer current class instance variable
B
invoke current class constructor
C
invoke current class method (implicitly)
D
to return the current class instance
E
All of the above
Question 2
Which of the following kinds of inner class is useful for short listeners used in only one place:
A
Member class
B
Anonymous class
C
Static member class
D
Local class
Question 2 Explanation: 
An inner class declared without a class name is known as anonymous inner class. We declare and instantiate them at the same time.
Question 3
Which of the following are legal lines of Java code? 1. int w = (int)769.7; 2. byte x = (byte)200L; 3. long y = (byte)150; 4. byte z = (byte)200L;
A
1 and 2
B
2 and 3
C
3 and 4
D
All of the above
Question 3 Explanation: 
(1) is correct because when a floating-point number is cast to an int, it simply loses the digits after the decimal. (2) and (4) are correct because a long can be cast into a byte. If the long is over 127, it loses its most significant (leftmost) bits. (3) actually works, even though a cast is not necessary, because a long can store a byte.
Question 4
Which of the following is correct about JDK, JVM & JRE:
A
Java Development Kit (JDK) is for development purpose and JVM is a part of it to execute the java programs.
B
JDK provides all the tools, executables and binaries required to compile, debug and execute a Java Program. The execution part is handled by JVM to provide machine independence.
C
Java Runtime Environment (JRE) is the implementation of JVM. JRE consists of JVM and java binaries and other classes to execute any program successfully
D
All of the above
Question 5
Which of the following is NOT a method of String class:
A
reverse()
B
equals()
C
substring()
D
compareTo()
Question 6
Which of these is immutable:
A
StringBuffer
B
String
C
StringBuilder
D
All are immutable
Question 7
Which class is the superclass of all classes:
A
Abstract
B
Math
C
Object
D
Process
Question 8
Which access modifier prevents access from another class within the same package:
A
public
B
protected
C
default
D
private
There are 8 questions to complete.
List
Return
Shaded items are complete.
12345
678
Return