Java Programming: Ultimate Quiz! MCQ

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Rushikesh
R
Rushikesh
Community Contributor
Quizzes Created: 4 | Total Attempts: 3,662
Questions: 20 | Attempts: 126

SettingsSettingsSettings
Java Programming: Ultimate Quiz! MCQ - Quiz

.


Questions and Answers
  • 1. 

    Which of the following are legal lines of Java code? 1. int w = (int)888.8; 2. byte x = (byte)100L; 3. long y = (byte)100; 4. byte z = (byte)100L;  

    • A.

      1 and 2

    • B.

      2 and 3

    • C.

      3 and 4

    • D.

      All statements are correct.

    Correct Answer
    D. All statements are correct.
    Explanation
    Explanation: Statements (1), (2), (3), and (4) are correct. (1) is correct because when a floating-point number (a double in this case) 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.

    Rate this question:

  • 2. 

    Which of these values can a boolean variable contain?

    • A.

      True and False

    • B.

      0 and 1

    • C.

      Any Integer value

    • D.

      True

    Correct Answer
    A. True and False
    Explanation
    Explanation: Boolean variable can contain only one of two possible values, true and false.

    Rate this question:

  • 3. 

    Which of these can be returned by the operator & ?

    • A.

      Integer

    • B.

      Boolean

    • C.

      Character

    • D.

      Integer or Boolean

    Correct Answer
    D. Integer or Boolean
    Explanation
    Explanation: We can use binary ampersand operator on integers/chars (and it returns an integer) or on booleans (and it returns a boolean).

    Rate this question:

  • 4. 

    What is the value stored in x in following lines of code?int x, y, z;x = 0;y = 1;x = y = z = 8;

    • A.

      0

    • B.

      1

    • C.

      9

    • D.

      8

    Correct Answer
    D. 8
    Explanation
    Explanation: none

    Rate this question:

  • 5. 

    Which of these are selection statements in Java?

    • A.

      If()

    • B.

      For()

    • C.

      Continue

    • D.

      Break

    Correct Answer
    A. If()
    Explanation
    Explanation: continue and break are jump statements, and for is an looping statement.

    Rate this question:

  • 6. 

    Which of the following is a method having same name as that of its class?

    • A.

      Finalize

    • B.

      Constructor

    • C.

      Class

    • D.

      Delete

    Correct Answer
    B. Constructor
    Explanation
    A constructor is a method that initializes an object immediately upon creation. It has the same name as that of class in which it resides

    Rate this question:

  • 7. 

    On applying Left shift operator, <<, on an integer bits are lost one they are shifted past which position bit?

    • A.

      1

    • B.

      31

    • C.

      32

    • D.

      33

    Correct Answer
    B. 31
    Explanation
    Explanation: The left shift operator shifts all of the bits in a value to the left specified number of times. For each shift left, the high order bit is shifted out and lost, zero is brought in from the right. When a left shift is applied to an integer operand, bits are lost once they are shifted past the bit position 31.

    Rate this question:

  • 8. 

    Which of these cannot be declared static?

    • A.

      Class

    • B.

      Object

    • C.

      Variable

    • D.

      Method

    Correct Answer
    B. Object
    Explanation
    Explanation: static statements are run as soon as class containing then is loaded, prior to any object declaration.

    Rate this question:

  • 9. 

     A class member declared protected becomes member of subclass of which type?

    • A.

      Public member

    • B.

      Private member

    • C.

      Protected member

    • D.

      Static member

    Correct Answer
    B. Private member
    Explanation
    Explanation: A class member declared protected becomes private member of subclass.

    Rate this question:

  • 10. 

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

    • A.

      Objectcopy()

    • B.

      Copy()

    • C.

      Object clone()

    • D.

      Clone()

    Correct Answer
    C. Object clone()
    Explanation
    The correct answer is "Object clone()". This method is a part of the Object class in Java and is used to create a copy or clone of an object. It returns a new object that is a copy of the original object.

    Rate this question:

  • 11. 

    Which of this method of class String is used to obtain the length of String object?

    • A.

      Get()

    • B.

      Sizeof()

    • C.

      Lengthof()

    • D.

      Length()

    Correct Answer
    D. Length()
    Explanation
    Explanation: Method length() of string class is used to get the length of the object which invoked method length().

    Rate this question:

  • 12. 

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

    Correct Answer
    B. Append()
    Explanation
    The method append() of class StringBuffer is used to concatenate the string representation to the end of the invoking string. This method appends the specified string to the existing string and returns a reference to the modified StringBuffer object. It is commonly used to build longer strings by appending smaller strings together.

    Rate this question:

  • 13. 

    Which of these keywords can be used to prevent Method overriding?

    • A.

      Static

    • B.

      Constant

    • C.

      Protected

    • D.

      Final

    Correct Answer
    D. Final
    Explanation
    Explanation: To disallow a method from being overridden, specify final as a modifier at the start of its declaration. Methods declared as final cannot be overridden.

    Rate this question:

  • 14. 

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

    Correct Answer
    A. GetBytes()
    Explanation
    Explanation: getBytes() stores the character in an array of bytes. It uses default character to byte conversions provided by the platform.

    Rate this question:

  • 15. 

    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.

    Correct Answer
    B. Packages
    Explanation
    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.

    Rate this question:

  • 16. 

    Which of these is an interface for control over serialization and deserialization?

    • A.

      Serializable

    • B.

      Externalization

    • C.

      FileFilter

    • D.

      ObjectInput

    Correct Answer
    B. Externalization
    Explanation
    Externalization is an interface for control over serialization and deserialization. It allows developers to have more control over the serialization process by implementing the Externalizable interface and providing their own custom serialization logic. This interface provides two methods, writeExternal() and readExternal(), which allow objects to write and read their own state in a customized manner. This is different from the Serializable interface, which provides a default serialization mechanism. FileFilter and ObjectInput are not interfaces for control over serialization and deserialization.

    Rate this question:

  • 17. 

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

    • A.

      RegionMatch()

    • B.

      Match()

    • C.

      RegionMatches()

    • D.

      RegionMatches()

    Correct Answer
    D. RegionMatches()
    Explanation
    The method regionMatches() is used to compare a specific region inside a string with another specific region in another string.

    Rate this question:

  • 18. 

    Which of these keywords is not a part of exception handling?

    • A.

      Try

    • B.

      Finally

    • C.

      Thrown

    • D.

      Catch

    Correct Answer
    C. Thrown
    Explanation
    Explanation: Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.

    Rate this question:

  • 19. 

    Which of these is a process of extracting/removing the state of an object from a stream?

    • A.

      Serialization

    • B.

      Externalization

    • C.

      File Filtering

    • D.

      Deserialization

    Correct Answer
    D. Deserialization
    Explanation
    Explanation: Deserialization is a process by which the data written in the stream can be extracted out from the stream.

    Rate this question:

  • 20. 

    Which of these is a super class of wrappers Double and Float?

    • A.

      Long

    • B.

      Digits

    • C.

      Float

    • D.

      Number

    Correct Answer
    D. Number
    Explanation
    Explanation: Number is an abstract/super class containing subclasses Double, Float, Byte, Short, Integer and Long.

    Rate this question:

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.