Java MCQ

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
Answer

a) -128 to 127

2) Which data type value is returned by all transcendental math functions?
a) int
b) float
c) double
d) long
Answer

c) double

3) Which of these coding types is used for data type characters in java?
a) UNICODE
b) ISO-LATIN-1
c) ASCII
d) None of the mentioned
Answer

a) UNICODE

4) Which of the following is a valid comment?
a)/*comment*//
b)/*comment/
c)//comment
d)*/comment
Answer

c) //comment

5) A character which gives the exact representation of data is called?
a)Variable
b)Literal
c)Identifier
d)Character
Answer

a) Variable

6) A character literal is enclosed in:
a) ' '
b) " "
c) ::
d) { }
Answer

a) ' '

7) A character literal is assigned to :
a)Char variable
b)String variable
c)Char type literal
d)String literal
Answer

a)Char variable

8) A set of characters is assigned to:
a) String variable
b) Static variable
c) Boolean variable
d) None
Answer

a) String variable

9) The ASCII codes of upper case alphabets range from :
a) 65 - 90
b)60 - 85
c)65 - 91
d)97 - 122
Answer

a) 65 - 90

10) Which of the following results in integer type?
a) 11.4F/3.2D
b) 13.8F/4.6F
c) 12/3
d) None
Answer

c) 12/3

11) Which of the following is a non-primitive data?
a)char
b) long
c) object
d) short
Answer

c) object

12) Which of the following is the exact representation of fractional values?
a)char
b) double
c) byte
d) String
Answer

b) double

13) Boolean data is used to test a particular condition i.e. true or false.Which of the following is a correct representation?
a)Boolean m=true
b)Boolean m='true'
c)Boolean m="true"
d) None
Answer

a) Boolean m=true

14) The statement n+= 4 is equivalent to :
a)++n
b) n=n+4
c) n+1
d) None
Answer

b) n=n+4

15) What will be the output of a and b in the following,if int a,b;a=10; b=a++;
a) 10,10
b) 10,11
c) 11,10
d) 11,11
Answer

b) 10,11

16) What will be the output of a++ when int a =-1;
a) 1
b) -1
c) 0
d) None
Answer

c) 0

17) If int a =25, b = 5,c=0; what value will be stored in c, when c =a%b?
a)5.0
b) 5
c)0
d) None
Answer

c) 0

18) What will be the value of m when the given statement is executed? int m=8; m*=8;
a)8
b)64
c)16
d) 88
Answer

b)64

19) double c; int x,y,z; x =5; y = 10; z=11; c=x*y+z/2;
a)55.0
b) 55.5
c)55
d) None
Answer

a) 55.0

20)int m, p; m = 5; p =0 ; p = m--+--m; The value of p will be:
a)11
b) 10
c)8
d)12
Answer

c) 8

21)int a=7, p=0, q=0; p=++a+--a; q-=p; The value of q will be :
a)13
b) 14
c)15
d)-15
Answer

a) -15

22) Which of these class is superclass of every class in java?
a) String class
b) Object class
c) Abstract class
d) ArrayList class
Answer

b) Object Class

23) Which of these method of Object class can clone an object?
a) Objectcopy()
b) copy()
c) Object clone()
d) clone()
Answer

a) Object clone()

24) Which of these method of Object class is used to obtain class of an object at run time?
a) get()
b) void getclass()
c) Class getclass()
d) None of the mentioned
Answer

c) Class getclass()

25) Which of these keywords can be used to prevent inheritance of a class?
a) super
b) constant
c) class
d) final
Answer

c) final

26) Which of these keywords cannot be used for a class which has been declared final?
a) abstract
b) extends
c) abstract and extends
d) None of the mentioned
Answer

c) abstract

27) Which inheritance in java is not supported?
a) Multiple inheritance using classes
b) Multiple inheritance using interfaces
c) Multilevel inheritance
d) Single inheritance
Answer

c) Multiple inheritance using classes

28) Which of these class refers upon its subclass for complete implementation of its methods?
a) Object class
b)Abstract class
c) ArrayList class
d) None of the mentioned
Answer

b) Abstract class

29) Which of these literals can be contained in float data type variable?
a) -1.7e+308
b)-3.4e+038
c) +1.7e+308
d) -3.4e+050
Answer

b) -3.4e+038

30) An expression involving byte, int, and literal numbers is promoted to which of these?
a) int
b) long
c) byte
d) float
Answer

a) int

31) What is the range of short data type in java?
a) -128 to 127
b) -2147483648 to 2147483647
c) -32768 to 32767
d) None of the mentioned
Answer

c) -32768 to 32767

32) What is subclass in java?
a) A subclass is a class that extends another class
b) A subclass is a class declared inside a class
c) Both the options (1) and (2) are correct
d) None of the above
Answer

a) A subclass is a class that extends another class

33) If class B is a subclass of class A then which is the correct syntax
a) class B:A{}
b) class B extends A{}
c) class B extends classA{}
d) class B implements A{}
Answer

b) Class B extends A { }

34) Advantage of inheritance in java programming is/are
a) Code Re-usability
b) Class Extendibility
c) Save development time
d) All
Answer

a) Code Re-usability

35) Which of the following is true about inheritance in Java?
A) Private methods are final
B) Protected members are accessible within a package and inherited classes outside the package
C) Protected methods are final
D) We cannot override private methods
a) A, B and D
b) Only A and B
c) A, B and C
d) B, C and D
Answer

a) A, B and D

36) A class member declared protected becomes a member of subclass of which type?
a) public member
b) private member
c) protected member
d) static member
Answer

a) private member

37) What is the numerical range of a char data type in Java?
a) 0 to 256
b) -128 to 127
c) 0 to 65535
d) 0 to 32767
Answer

c) 0 to 65535

38) Which of these methods is used to obtain value of invoking object as a long?
a) long value()
b) long longValue()
c) Long longvalue()
d) Long Longvalue()
Answer

b) long longValue()

39) Which of the following is method of wrapper Integer for converting the value of an object into int?
a) bytevalue()
b) int intValue();
c) Bytevalue()
d) Byte Bytevalue()
Answer

b) int intValue();

40) Which class provides system-independent server-side implementation?
a) Server
b) ServerReader
c) Socket
d) ServerSocket
Answer

d) ServerSocket

41) Which of these is a wrapper for simple data type char?
a) Float
b) Character
c) String
d) Integer
Answer

b) Character

42) Which of these is a super class of wrappers Long, Character & Integer?
a) Long
b) Digits
c) Float
d) Number
Answer

d) Number

43) 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()
Answer

b) int hashcode()

Go Checkout :- More Mcq Questions on Java.
Go Checkout :- Blog on Java Programming language.