Java Programming - Level 1

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,740
Questions: 30 | Attempts: 1,118

SettingsSettingsSettings
Java Quizzes & Trivia

Questions and Answers
  • 1. 

    What is the range of short data types in Java?

    • A.

      -128 to 127

    • B.

      -32768 to 32767

    • C.

      -2147483648 to 2147483647

    • D.

      None of the mentioned

    Correct Answer
    B. -32768 to 32767
    Explanation
    Explanation: Short occupies 16 bits in memory. Its range is from -32768 to 32767.

    Rate this question:

  • 2. 

    What is the numerical range of a char data type in Java?

    • A.

      -128 to 127

    • B.

      0 to 256

    • C.

      0 to 32767

    • D.

      0 to 65535

    Correct Answer
    D. 0 to 65535
    Explanation
    Explanation: Char occupies 16-bit in memory, so it supports 2^16 i:e from 0 to 65535.

    Rate this question:

  • 3. 

    Which of these is a long data type literal?

    • A.

      0x99fffL

    • B.

      ABCDEFG

    • C.

      0x99fffa

    • D.

      99671246

    Correct Answer
    A. 0x99fffL
    Explanation
    Explanation: Data type long literals are appended by an upper or lowercase L. 0x99fffL is hexadecimal long literal.

    Rate this question:

  • 4. 

    Which of these operators is used to allocate memory to array variables in Java?

    • A.

      Malloc

    • B.

      Alloc

    • C.

      New

    • D.

      New malloc

    Correct Answer
    C. New
    Explanation
    Operator new allocates a block of memory specified by the size of array, and gives the reference of memory allocated to the array variable.

    Rate this question:

  • 5. 

    Which of these is not a bitwise operator?

    • A.

      &

    • B.

      &=

    • C.

      !=

    • D.

    Correct Answer
    D.
    Explanation
    Explanation:

    Rate this question:

  • 6. 

    What is the output of relational operators?

    • A.

      Integer

    • B.

      Boolean

    • C.

      Characters

    • D.

      Double

    Correct Answer
    B. Boolean
    Explanation
    Explanation: None

    Rate this question:

  • 7. 

    Which of these have highest precedence?

    • A.

      ( )

    • B.

      ++

    • C.

      *

    • D.

      >>

    Correct Answer
    A. ( )
    Explanation
    Explanation: Order of precedence is (highest to lowest) a -> b -> c -> d.

    Rate this question:

  • 8. 

     Which of these selection statements test only for equality?

    • A.

      If

    • B.

      Switch

    • C.

      If & switch

    • D.

      None of the mentioned

    Correct Answer
    B. Switch
    Explanation
    Explanation: switch statements checks for equality between the controlling variable and its constant cases.

    Rate this question:

  • 9. 

    What is the stored in the object obj in following lines of code? box obj;

    • A.

      Memory address of allocated memory of object.

    • B.

      NULL

    • C.

      Any arbitrary pointer

    • D.

      Garbage

    Correct Answer
    B. NULL
    Explanation
    Explanation: Memory is allocated to an object using new operator. box obj; just declares a reference to object, no memory is allocated to it hence it points to NULL

    Rate this question:

  • 10. 

    What is the return type of a method that does not returns any value?

    • A.

      Int

    • B.

      Float

    • C.

      Void

    • D.

      Double

    Correct Answer
    C. Void
    Explanation
    Explanation: void method does not return any value.

    Rate this question:

  • 11. 

     What is the return type of Constructors?

    • A.

      Int

    • B.

      Float

    • C.

      Void

    • D.

      None of the mentioned

    Correct Answer
    A. Int
    Explanation
    Explanation: Constructors does not have any return type, not even void.

    Rate this question:

  • 12. 

    What is a process of defining two or more methods within the same class that have the same name but different parameters declaration?

    • A.

      Method overloading

    • B.

      Method overriding

    • C.

      Method hiding

    • D.

      None of the mentioned

    Correct Answer
    A. Method overloading
    Explanation
    Explanation: Two or more methods can have the same name as long as their parameters declaration is different, the methods are said to be overloaded and the process is called method overloading. Method overloading is a way by which Java implements polymorphism.

    Rate this question:

  • 13. 

     Which of these access specifiers must be used for main() method?

    • A.

      Private

    • B.

      Public

    • C.

      Protected

    • D.

      None of the mentioned

    Correct Answer
    B. Public
    Explanation
    Explanation: main() method must be specified public as it called by Java run time system, outside of the program. If no access specifier is used then by default member is public within its own package & cannot be accessed by Java run time system.

    Rate this question:

  • 14. 

    Arrays in Java are implemented as?

    • A.

      Class

    • B.

      Object

    • C.

      Variable

    • D.

      None of the mentioned

    Correct Answer
    B. Object
    Explanation
    Explanation: Array is object container which is used to hold a collection of fixed value having the same type.

    Rate this question:

  • 15. 

    String in Java is a?

    • A.

      Class

    • B.

      Object

    • C.

      Variable

    • D.

      Character array

    Correct Answer
    A. Class
    Explanation
    Explanation: None

    Rate this question:

  • 16. 

    Which of ​this keyword must be used to inherit a class?

    • A.

      Super

    • B.

      This

    • C.

      Extents

    • D.

      Extends

    Correct Answer
    D. Extends
    Explanation
    The keyword "extends" must be used to inherit a class. Inheritance is a mechanism in object-oriented programming that allows a class to inherit the properties and methods of another class. By using the "extends" keyword, a subclass can inherit the attributes and behaviors of a superclass, enabling code reuse and promoting a hierarchical structure in the program.

    Rate this question:

  • 17. 

    Which of these keywords can be used in subclass to call the constructor of superclass?

    • A.

      Super

    • B.

      This

    • C.

      Extent

    • D.

      Extends

    Correct Answer
    A. Super
    Explanation
    The keyword "super" can be used in a subclass to call the constructor of the superclass. It is used to invoke the superclass constructor and initialize the inherited members of the subclass. This allows the subclass to inherit and utilize the functionality of the superclass while also adding its own unique features.

    Rate this question:

  • 18. 

    Which of these class is superclass of every class in Java?

    • A.

      String class

    • B.

      Object class

    • C.

      Abstract class

    • D.

      ArrayList class

    Correct Answer
    B. Object class
    Explanation
    Explanation: Object class is a superclass of every class in java

    Rate this question:

  • 19. 

     Which of these class is superclass of String and StringBuffer class?

    • A.

      Java.util

    • B.

      Java.lang

    • C.

      ArrayList

    • D.

      None of the mentioned

    Correct Answer
    B. Java.lang
    Explanation
    The correct answer is "java.lang" because the java.lang package contains fundamental classes and interfaces that are essential to the Java programming language. String and StringBuffer classes are both part of this package, making it the superclass of both.

    Rate this question:

  • 20. 

    Which of these method of class String is used to extract more than one character at a time a String object?

    • A.

      Getchars()

    • B.

      GetChars()

    • C.

      Getchars()

    • D.

      GetChars()

    Correct Answer
    D. GetChars()
    Explanation
    The method getChars() is used to extract more than one character at a time from a String object.

    Rate this question:

  • 21. 

    Which of these method of class String is used to compare two String objects for their equality?

    • A.

      Equals()

    • B.

      Equals()

    • C.

      Isequal()

    • D.

      Isequal()

    Correct Answer
    A. Equals()
    Explanation
    The method "equals()" is used to compare two String objects for their equality. This method checks if the content of the two strings is the same, regardless of their memory location. It returns a boolean value, true if the strings are equal, and false if they are not.

    Rate this question:

  • 22. 

    Which of these method of class String is used to extract a substring from a String object?

    • A.

      Substring()

    • B.

      Substring()

    • C.

      SubString()

    • D.

      None of the mentioned

    Correct Answer
    A. Substring()
    Explanation
    The correct answer is substring(). This method is used to extract a substring from a String object. It takes two parameters, the starting index and the ending index, and returns a new string that is a subset of the original string. The substring() method is case-sensitive and the ending index is exclusive, meaning it does not include the character at that index in the substring.

    Rate this question:

  • 23. 

    Which of these class is used to create an object whose character sequence is mutable?

    • A.

      String()

    • B.

      StringBuffer()

    • C.

      Both of the metioned

    • D.

      None of the mentioned

    Correct Answer
    B. StringBuffer()
    Explanation
    Explanation: StringBuffer represents growable and writeable character sequence.

    Rate this question:

  • 24. 

    Which of these keywords is used to define packages in Java?

    • A.

      Pkg

    • B.

      Pkg

    • C.

      Package

    • D.

      Package

    Correct Answer
    C. Package
    Explanation
    The keyword "package" is used to define packages in Java. Packages are used to organize classes and interfaces into groups, making it easier to manage and maintain large codebases. By using the "package" keyword followed by the package name, developers can create a hierarchical structure for their code. This allows for better organization, reusability, and encapsulation of code.

    Rate this question:

  • 25. 

     Which of these keywords is used to define interfaces in Java?

    • A.

      Interface

    • B.

      Interface

    • C.

      Intf

    • D.

      Intf

    Correct Answer
    A. Interface
    Explanation
    The keyword "interface" is used to define interfaces in Java. In Java, an interface is a collection of abstract methods that can be implemented by a class. It defines a contract that a class must adhere to if it wants to implement that interface. The other options "Interface", "intf", and "Intf" are not valid keywords in Java for defining interfaces.

    Rate this question:

  • 26. 

    Which of these classes is not included in java.lang?

    • A.

      Byte

    • B.

      Integer

    • C.

      Array

    • D.

      Class

    Correct Answer
    C. Array
    Explanation
    Explanation: Array class is a member of a java.util

    Rate this question:

  • 27. 

    Which of these class have only one field ‘TYPE’?

    • A.

      Void

    • B.

      Process

    • C.

      System

    • D.

      Runtime

    Correct Answer
    A. Void
    Explanation
    Explanation: The Void class has one field, TYPE, which holds a reference to the Class object for the type void.

    Rate this question:

  • 28. 

    Which of these class is superclass of all other classes?

    • A.

      Math

    • B.

      Process

    • C.

      System

    • D.

      Object

    Correct Answer
    D. Object
    Explanation
    The correct answer is "Object" because in Java, the Object class is the root class for all other classes. It is at the top of the class hierarchy and serves as the superclass for all other classes. Every class in Java directly or indirectly extends the Object class, which provides basic functionalities and methods that are inherited by all other classes.

    Rate this question:

  • 29. 

    Which of these class is used for input and output operation when working with bytes?

    • A.

      InputStream

    • B.

      Reader

    • C.

      Writer

    • D.

      All of the mentioned

    Correct Answer
    A. InputStream
    Explanation
    Explanation: InputStream & OutputStream are designed for byte stream. Reader and writer are designed for character stream.

    Rate this question:

  • 30. 

    Which of these is a process of writing the state of an object to a byte stream?

    • A.

      Serialization

    • B.

      Externalization

    • C.

      File Filterning

    • D.

      All of the mentioned

    Correct Answer
    A. Serialization
    Explanation
    Serialization is the process of writing the state of an object to a byte stream. This is used when you want to save the state of your program to the persistent storage area.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 17, 2017
    Quiz Created by
    Rushikesh
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.