Java Language | 30 Minute‐Test 8


Instruction

  • Total number of questions : 30.
  • Time alloted : 30 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

What is the range of byte data type in Java?

A.
-128 to 127
B.
-32768 to 32767
C.
-2147483648 to 2147483647
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Byte occupies 8 bits in memory. Its range is from -128 to 127.

2.

Which of these coding types is used for data type characters in Java?

A.
ASCII
B.
ISO-LATIN-1
C.
UNICODE
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Unicode defines fully international character set that can represent all the characters found in all human languages. Its range is from 0 to 65536.

3.

Which of these can be returned by the operator & ?

A.
Integer
B.
Boolean
C.
Character
D.
Integer or Boolean

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

We can use binary ampersand operator on integers/chars (and it returns an integer) or on booleans (and it returns a boolean).

4.

What is the prototype of the default constructor of this class?
public class prototype { }

A.
prototype( )
B.
prototype(void)
C.
public prototype(void)
D.
public prototype( )

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

5.

What is the output of this program?

    class array_output {

        public static void main(String args[])

        {

            int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};

            int sum = 0;

            for (int i = 0; i < 3; ++i)

                for (int j = 0; j <  3 ; ++j)

                    sum = sum + array_variable[i][j];

            System.out.print(sum / 5);

        }

    }

A.
8
B.
9
C.
10
D.
11

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

6.

Modulus operator, %, can be applied to which of these?

A.
Integers
B.
Floating – point numbers
C.
Both Integers and floating – point numbers.
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Modulus operator can be applied to both integers and floating point numbers. .

7.

Which operator is used to invert all the digits in binary representation of a number?

A.
~
B.
<<<
C.
>>>
D.
^

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Unary not operator, ~, inverts all of the bits of its operand in binary representation.

8.

Which of these is returned by “greater than”, “less than” and “equal to” operators?

A.
Integers
B.
Floating – point numbers
C.
Boolean
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

All relational operators return a boolean value ie. true and false.

9.

What should be expression1 evaluate to in using ternary operator as in this line?
expression1 ? expression2 : expression3

A.
Integer
B.
Floating – point numbers
C.
Boolean
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The controlling condition of ternary operator must evaluate to boolean.

10.

Which of these are selection statements in Java?

A.
if()
B.
for()
C.
continue
D.
break

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

continue and break are jump statements, and for is an looping statement.

11.

Which of these keywords is used to make a class?

A.
class
B.
struct
C.
int
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

12.

What is the process of defining more than one method in a class differentiated by method signature?

A.
Function overriding
B.
Function overloading
C.
Function doubling
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or parameters type and number. Example – int volume(int length, int width) & int volume(int length , int width , int height) can be used to calculate volume.

13.

Which keyword is used by method to refer to the object that invoked it?

A.
import
B.
catch
C.
abstract
D.
this

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

this keyword can be used inside any method to refer to the current object. this is always a reference to the object on which the method was invoked.

14.

Which of these can be overloaded?

A.
Methods
B.
Constructors
C.
All of the mentioned
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

15.

Which of these is used to access member of class before object of that class is created?

A.
public
B.
private
C.
static
D.
protected

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

16.

Which of these keywords is used to prevent content of a variable from being modified?

A.
final
B.
last
C.
constant
D.
static

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

A variable can be declared final, doing so prevents its content from being modified. Final variables must be initialized when it is declared.

17.

Which of these method of String class is used to obtain character at specified index?

A.
char()
B.
Charat()
C.
charat()
D.
charAt()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

18.

Which of these keywords is used to refer to member of base class from a sub class?

A.
upper
B.
super
C.
this
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super.

19.

What is the process of defining a method in subclass having same name & type signature as a method in its superclass?

A.
Method overloading
B.
Method overriding
C.
Method hiding
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

20.

Which of these method of Object class can clone an object?

A.
Objectcopy()
B.
copy()
C.
Object clone()
D.
clone()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

21.

Which of these operators can be used to concatenate two or more String objects?

A.
+
B.
+=
C.
&
D.
||

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

operator + is used to concatenate strings, Example String s = “i ” + “like ” + “java”; String s contains “I like java”

22.

Which of these methods is an alternative to getChars() that stores the characters in an array of bytes?

A.
getBytes()
B.
GetByte()
C.
giveByte()
D.
Give Bytes()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

getBytes() stores the character in an array of bytes. It uses default character to byte conversions provided by platform.

23.

What will s2 contain after following lines of code?
String s1 = “one”;
String s2 = s1.concat(“two”)

A.
one
B.
two
C.
onetwo
D.
twoone

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Two strings can be concatenated by using concat() method.

24.

Which of these method of class StringBuffer is used to concatenate the string representation to the end of invoking string?

A.
concat()
B.
append()
C.
join()
D.
concatenate()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

25.

What will s2 contain after following lines of code?
StringBuffer s1 = “one”;
StringBuffer s2 = s1.append(“two”)

A.
one
B.
two
C.
onetwo
D.
twoone

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Two strings can be concatenated by using append() method.

26.

Which of these methods is used to compare a specific region inside a string with another specific region in another string?

A.
regionMatch()
B.
match()
C.
RegionMatches()
D.
regionMatches()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

27.

Which of these is a mechanism for naming and visibility control of a class and its content?

A.
Object
B.
Packages
C.
Interfaces
D.
None of the Mentioned.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Packages are both naming and visibility control mechanism. We can define a class inside a package which is not accessible by code outside the package.

28.

Which of these can be used to fully abstract a class from its implementation?

A.
Objects
B.
Packages
C.
Interfaces
D.
None of the Mentioned.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

29.

Which of these is a process of converting a simple data type into a class?

A.
type wrapping
B.
type conversion
C.
type casting
D.
None of the Mentioned.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

30.

Which of the following methods is a method of wrapper Integer for obtaining hash code for the invoking object?

A.
int hash()
B.
int hashcode()
C.
int hashCode()
D.
Integer hashcode()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

Submit your test now to view the Results and Statistics with answer explanation.