Java Language | 30 Minute‐Test 2


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.

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Range of float data type is -(3.4e38) To +(3.4e38)

2.

Which one is a valid declaration of a boolean?

A.
boolean b1 = 1;
B.
boolean b2 = ‘false’;
C.
boolean b3 = false;
D.
boolean b4 = ‘true’

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Boolean can only be assigned true or false literals.

3.

Which of these can not be used for a variable name in Java?

A.
identifier
B.
keyword
C.
identifier & keyword
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Keywords are specially reserved words which can not be used for naming a user defined variable, example : class, int, for etc.

4.

What is Truncation is Java?

A.
Floating-point value assigned to an integer type.
B.
Integer value assigned to floating type
C.
Floating-point value assigned to an Floating type.
D.
Integer value assigned to floating type.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

5.

Which of these is necessary to specify at time of array initialization?

A.
Row
B.
Column
C.
Both Row and Column
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

6.

Which of these statements are incorrect?

A.
Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms.
B.
Assignment operators run faster than their equivalent long forms.
C.
Assignment operators can be used only with numeric and character data type.
D.
None

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

7.

Which of these statements are incorrect?

A.
The left shift operator, <<, shifts all of the bits in a value to the left specified number of times.
B.
The right shift operator, >>, shifts all of the bits in a value to the right specified number of times.
C.
The left shift operator can be used as an alternative to multiplying by 2.
D.
The right shift operator automatically fills the higher order bits with 0.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The right shift operator automatically fills the higher order bit with its previous contents each time a shift occurs. This also preserves the sign of the value.

8.

Which of these statement is correct?

A.
true and false are numeric values 1 and 0.
B.
true and false are numeric values 0 and 1.
C.
true is any non zero value and false is 0.
D.
true and false are non numeric values.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

true and false are keywords, they are non numeric values which do no relate to zero or non zero numbers. true and false are boolean values.

9.

Which of these statements are incorrect?

A.
Equal to operator has least precedence.
B.
Brackets () have highest precedence.
C.
Division operator, /, has higher precedence than multiplication operator.
D.
Addition operator, +, and subtraction operator have equal precedence.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Division operator, /, has equal precedence as of multiplication operator. In expression involving multiplication and division evaluation of expression will begin from right side when no brackets are used.

10.

Which of these statement is incorrect?

A.
switch statement is more efficient than a set of nested if.
B.
two case constants in the same switch can have identical values.
C.
switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression.
D.
it is possible to create a nested switch statements.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

No two case constants in the same switch can have identical values.

11.

Which of these statement is incorrect?

A.
Every class must contain a main() method.
B.
Applets do not require a main() method at all.
C.
There can be only one main() method in a program.
D.
main() method must be made public.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Every class does not need to have a main() method, there can be only one main() method which is made public.

12.

Which of these statement is incorrect?

A.
All object of a class are allotted memory for the all the variables defined in the class.
B.
If a function is defined public it can be accessed by object of other class by inheritation.
C.
main() method must be made public.
D.
All object of a class are allotted memory for the methods defined in the class.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

All object of class share a single copy of methods defined in a class, Methods are allotted memory only once. All the objects of the class have access to methods of that class are allotted memory only for the variables not for the methods.

13.

Which function is used to perform some action when the object is to be destroyed?

A.
finalize()
B.
delete()
C.
main()
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

14.

What is the output of the following code?

class San

{

public void m1 (int i,float f)

{

 System.out.println(" int float method");

}

  public void m1(float f,int i);

 {

 System.out.println("float int method");

 }

   public static void main(String[]args)

 {

    San s=new San();

        s.m1(20,20);

 }

}

A.
int float method
B.
float int method
C.
compile time error
D.
run time error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

While resolving overloaded method, compiler automatically promotes if exact match is not found. But in this case, which one to promote is an ambiguity.

15.

Which of the following statements are incorrect?

A.
public members of class can be accessed by any code in the program.
B.
private members of class can only be accessed by other members of the class.
C.
private members of class can be inherited by a sub class, and become protected members in sub class.
D.
protected members of a class can be inherited by a sub class, and become private members of the sub class.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

private members of a class can not be inherited by a sub class.

16.

Which of the following statements are incorrect?

A.
Variables declared as final occupy memory.
B.
final variable must be initialized at the time of declaration.
C.
Arrays in java are implemented as an object.
D.
All arrays contain an attribute-length which contains the number of elements stored in the array.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

17.

Which of the following statements are incorrect?

A.
String is a class.
B.
Strings in java are mutable.
C.
Every string is an object of class String.
D.
Java defines a peer class of String, called StringBuffer, which allows string to be altered.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Strings in Java are immutable that is they can not be modified.

18.

What is the output of this program?

    class A {

        public int i;

        protected int j;

    }   

    class B extends A {

        int j;

        void display() {

            super.j = 3;

            System.out.println(i + " " + j);

        }

    }   

    class Output {

        public static void main(String args[])

        {

            B obj = new B();

            obj.i=1;

            obj.j=2;  

            obj.display();    

        }

   }

A.
1 2
B.
2 1
C.
1 3
D.
3 1

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Both class A & B have member with same name that is j, member of class B will be called by default if no specifier is used. I contains 1 & j contains 2, printing 1 2.

19.

At line number 2 below, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”

public interface Status

   {

        /* insert qualifier here */ int MY_VALUE = 10;

   }

A.
final, native, private
B.
final, static, protected
C.
final, private, abstract
D.
final, static, public

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Every interface variable is implicitly public static and final.

20.

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

A abstract class is incomplete by itself and relies upon its subclasses to provide complete implementation. If we declare a class final then no class can inherit that class, an abstract class needs its subclasses hence both final and abstract cannot be used for a same class.

21.

Which of these constructors is used to create an empty String object?

A.
String()
B.
String(void)
C.
String(0)
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None .

22.

Which of these methods can be used to convert all characters in a String into a character array?

A.
charAt()
B.
both getChars() & charAt()
C.
both toCharArray() & getChars()
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

charAt() return one character only not array of character.

23.

Which of the following statement is correct?

A.
replace() method replaces all occurrences of one character in invoking string with another character.
B.
replace() method replaces only first occurances of a character in invoking string with another character.
C.
replace() method replaces all the characters in invoking string with another character.
D.
replace() replace() method replaces last occurrence of a character in invoking string with another character.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

replace() method replaces all occurrences of one character in invoking string with another character.

24.

Which of the following statement is correct?

A.
reverse() method reverses all characters.
B.
reverseall() method reverses all characters.
C.
replace() method replaces first occurrence of a character in invoking string with another character.
D.
replace() method replaces last occurrence of a character in invoking string with another character.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

reverse() method reverses all characters. It returns the reversed object on which it was called.

25.

Which of the following are incorrect form of StringBuffer class constructor?

A.
StringBuffer()
B.
StringBuffer(int size)
C.
StringBuffer(String str)
D.
StringBuffer(int size , String str)

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

26.

Which of these data type value is returned by equals() method of String class?

A.
char
B.
int
C.
boolean
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

equals() method of string class returns boolean value true if both the string are equal and false if they are unequal.

27.

Which of the following is correct way of importing an entire package ‘pkg’?

A.
import pkg.
B.
Import pkg.
C.
import pkg.*
D.
Import pkg.*

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Operator * is used to import the entire package.

28.

Which of the following is correct way of implementing an interface salary by class manager?

A.
class manager extends salary {}
B.
class manager implements salary {}
C.
class manager imports salary {}
D.
None of the mentioned.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

29.

Which of the following is method of wrapper Float for converting the value of an object into byte?

A.
bytevalue()
B.
byte byteValue()
C.
Bytevalue()
D.
Byte Bytevalue().

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

30.

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().

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

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