Could You Pass This Java Quiz? Test!

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 Divya
D
Divya
Community Contributor
Quizzes Created: 1 | Total Attempts: 149
Questions: 30 | Attempts: 149

SettingsSettingsSettings
Could You Pass This Java Quiz? Test! - Quiz

.


Questions and Answers
  • 1. 

    Which one among these are OOPS features?

    • A.

      Inheritance

    • B.

      Class

    • C.

      Methods

    • D.

      None

    Correct Answer
    A. Inheritance
    Explanation
    Inheritance is one of the features of Object-Oriented Programming (OOPS). It allows a class to inherit properties and behaviors from another class, known as the parent or base class. This promotes code reusability and allows for the creation of hierarchical relationships between classes. Inheritance helps in organizing and structuring code by creating a hierarchy of classes, where each class inherits attributes and methods from its parent class. Therefore, inheritance is a fundamental concept in OOPS.

    Rate this question:

  • 2. 

    What is the extension for java programs?

    • A.

      .cpp

    • B.

      .js

    • C.

      .c

    • D.

      .java

    Correct Answer
    D. .java
    Explanation
    The extension for Java programs is ".java" because it is the standard file extension used for Java source code files. This extension allows the Java compiler and IDEs to recognize and properly handle the file as a Java program.

    Rate this question:

  • 3. 

    Example of compile-time polymorphism.

    • A.

      Method Overloading

    • B.

      Method Overriding

    • C.

      Abstraction

    • D.

      Encapsulation

    Correct Answer
    A. Method Overloading
    Explanation
    Method overloading is an example of compile-time polymorphism. It allows multiple methods with the same name but different parameters to coexist in a class. During compilation, the appropriate method is selected based on the number and types of arguments provided. This enables the programmer to perform different operations using the same method name, providing flexibility and code reusability.

    Rate this question:

  • 4. 

    What is the data type of array which we used as a parameter to the main method?

    • A.

      Int

    • B.

      Char

    • C.

      String

    • D.

      Double

    Correct Answer
    C. String
    Explanation
    The data type of the array used as a parameter to the main method is String. This is because in Java, the main method can take an array of Strings as a parameter, which allows command-line arguments to be passed to the program.

    Rate this question:

  • 5. 

    The main method can be overridden.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The main method in Java cannot be overridden because it is a static method. Overriding is a concept that applies to instance methods, where a subclass can provide its own implementation of a method defined in the superclass. However, the main method is a special method that serves as the entry point for a Java program, and it is declared as static. Static methods are associated with the class itself, not with any particular instance of the class, so they cannot be overridden. Therefore, the statement that the main method can be overridden is false.

    Rate this question:

  • 6. 

    From the following statements which is a disadvantage of an java array?

    • A.

      An array can hold primitive types data

    • B.

      An array has its size that is known as array length

    • C.

      An array knows only its type that it contains. Array type is checked at the compile-time

    • D.

      An array holds only one type of data

    Correct Answer
    D. An array holds only one type of data
    Explanation
    An array holds only one type of data, which is a disadvantage because it limits the flexibility and versatility of the array. If we need to store different types of data in the same array, we would need to create separate arrays for each type, leading to increased complexity and reduced code efficiency. This limitation can be problematic when dealing with complex data structures or when we want to store heterogeneous data.

    Rate this question:

  • 7. 

    Which provides accessibility to classes and interface? 

    • A.

      import

    • B.

      Static import

    • C.

      None of the above

    • D.

      All of above

    Correct Answer
    A. import
    Explanation
    The "import" keyword in Java provides accessibility to classes and interfaces. It is used to include a package or a specific class from a package, allowing the programmer to use the classes and interfaces defined in that package in their code. By importing the necessary classes and interfaces, the programmer can access their methods, variables, and other members without having to use their fully qualified names.

    Rate this question:

  • 8. 

    Why do we need to write static keyword to the main method?

    • A.

      To create single copy

    • B.

      It is in syntax

    • C.

      It give access to other method

    • D.

      None

    Correct Answer
    A. To create single copy
    Explanation
    The static keyword is used in the main method because it allows the method to be accessed without creating an instance of the class. This means that there is only one copy of the main method that can be accessed by the JVM, making it the entry point for the program. Without the static keyword, multiple copies of the main method would be created, which would cause confusion and potentially lead to errors.

    Rate this question:

  • 9. 

    Methods of the interface are _______ in nature.

    • A.

      Abstract

    • B.

      Variable

    • C.

      Static

    • D.

      None of these

    Correct Answer
    A. Abstract
    Explanation
    The methods of an interface are abstract in nature because they do not have a body or implementation. They only have method signatures, which define the name, parameters, and return type of the method. The actual implementation of the method is provided by the classes that implement the interface. This allows for multiple classes to provide their own implementation of the methods defined in the interface, promoting code reusability and allowing for polymorphism.

    Rate this question:

  • 10. 

    What can be accessed or inherited without an actual copy of code to each program? 

    • A.

      Browser

    • B.

      Applet

    • C.

      Package

    • D.

      None of the above

    Correct Answer
    C. Package
    Explanation
    Packages in programming allow for the organization and grouping of related code. They provide a way to access and inherit code without the need for an actual copy in each program. By importing a package, the code contained within it can be accessed and used by different programs. This promotes code reusability and modularity, making it easier to manage and maintain large projects. Therefore, the correct answer is "Package".

    Rate this question:

  • 11. 

    Switch is more efficient than nested if or if - else in java. 

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The statement is true because a switch statement in Java can be more efficient than using nested if or if-else statements. This is because a switch statement allows for multiple cases to be evaluated at once, while nested if or if-else statements require each condition to be checked one by one. Additionally, a switch statement can be optimized by the Java compiler, resulting in faster execution. Therefore, using a switch statement can improve the efficiency and readability of the code.

    Rate this question:

  • 12. 

    Which package includes all the standard classes of java? 

    • A.

      java.lang

    • B.

      Java.math

    • C.

      Java.ref

    • D.

      Java.util

    Correct Answer
    A. java.lang
    Explanation
    The package "java.lang" includes all the standard classes of Java. This package is automatically imported in every Java program and contains fundamental classes such as String, Integer, Boolean, and Object. These classes provide basic functionality and are essential for writing Java programs.

    Rate this question:

  • 13. 

    JVM stands for? 

    • A.

      Java Very Large Machine

    • B.

      Java Verified Machine

    • C.

      Java Very Small Machine

    • D.

      Java Virtual Machine

    Correct Answer
    D. Java Virtual Machine
    Explanation
    JVM stands for Java Virtual Machine. It is a virtual machine that allows Java programs to run on different platforms without the need for recompilation. The JVM provides a runtime environment for executing Java bytecode, which is generated from Java source code. It is responsible for memory management, garbage collection, and executing the instructions of the Java program. The other options, Java Very Large Machine, Java Verified Machine, and Java Very Small Machine, are not correct definitions for JVM.

    Rate this question:

  • 14. 

    Who is also called the father of Java Programming Language? 

    • A.

      James Gosling

    • B.

      Ken Thompson

    • C.

      Dennis Richie

    • D.

      None of the above

    Correct Answer
    A. James Gosling
    Explanation
    James Gosling is known as the father of Java Programming Language because he is the original designer of the language. He developed Java in the mid-1990s while working at Sun Microsystems. Gosling's contributions to the development of Java include designing its syntax, creating the original compiler and virtual machine, and defining its core libraries. His work has had a significant impact on the field of programming and has made Java one of the most widely used programming languages in the world.

    Rate this question:

  • 15. 

    Generally, the string is a sequence of characters, But in java, the string is an _______. 

    • A.

      Object

    • B.

      Class

    • C.

      Package

    • D.

      Method

    Correct Answer
    A. Object
    Explanation
    In Java, the string is an object. In object-oriented programming, objects are instances of classes that have properties and behaviors. The String class in Java represents a sequence of characters and provides various methods to manipulate and work with strings. Since strings in Java have properties and behaviors, they are considered objects rather than just a sequence of characters.

    Rate this question:

  • 16. 

    Which is nothing but a blueprint or a template for creating different objects which define its properties and behaviors? 

    • A.

      An Array

    • B.

      A class

    • C.

      Interface

    • D.

      None of the above

    Correct Answer
    B. A class
    Explanation
    A class is a blueprint or a template for creating different objects. It defines the properties and behaviors that the objects of that class will have. Objects created from a class will have the same structure and behavior as defined in the class. Therefore, a class is the correct answer as it best fits the description of being a blueprint or template for creating objects.

    Rate this question:

  • 17. 

    If a class has multiple methods by the same name but different parameters, it is known as? 

    • A.

      Constructor overloading

    • B.

      Method overloading

    • C.

      Method overriding

    • D.

      Operator overloading

    Correct Answer
    B. Method overloading
    Explanation
    Method overloading occurs when a class has multiple methods with the same name but different parameters. This allows the class to perform different actions based on the type or number of arguments passed to the method. It is a way to create multiple methods with the same name but with different functionality, improving code readability and reusability. This concept is widely used in object-oriented programming languages like Java and C++.

    Rate this question:

  • 18. 

    Which specification provides a runtime environment in which java byte code can be executed? 

    • A.

      JDK

    • B.

      JVM

    • C.

      JRE

    • D.

      None of the above

    Correct Answer
    B. JVM
    Explanation
    JVM stands for Java Virtual Machine, which is a specification that provides a runtime environment for executing Java byte code. It is responsible for interpreting the byte code and executing the instructions on the underlying hardware or operating system. JVM also provides various services like memory management, garbage collection, and exception handling. JDK (Java Development Kit) is a software development kit that includes tools for developing Java applications, including the JVM. JRE (Java Runtime Environment) is a subset of JDK that only includes the JVM and necessary libraries for running Java applications. Therefore, the correct answer is JVM.

    Rate this question:

  • 19. 

    What output you will get if you run this program? class Modulus { public static void main(String args[]) { int x = 42; double y = 42.25; System.out.println("x mod 10 = " + x % 10); System.out.println("y mod 10 = " + y % 10); } } 

    • A.

      X mod 10 = 2 y mod 10 = 2.25

    • B.

      x mod 10 = 4 y mod 10 = 2.50

    • C.

      X mod 10 = 6 y mod 10 = 3.25

    • D.

      x mod 10 = 2 y mod 10 = 4.25

    Correct Answer
    A. X mod 10 = 2 y mod 10 = 2.25
    Explanation
    The program calculates the remainder when x and y are divided by 10 using the modulus operator (%). In the case of x, 42 divided by 10 leaves a remainder of 2. In the case of y, 42.25 divided by 10 leaves a remainder of 2.25.

    Rate this question:

  • 20. 

    The following Syntax is used for?class Subclass-name extends Superclass-name { //methods and fields } 

    • A.

      Polymorphism

    • B.

      Encapsulation

    • C.

      Inheritance

    • D.

      None of the above

    Correct Answer
    C. Inheritance
    Explanation
    The given syntax is used for inheritance. Inheritance is a mechanism in object-oriented programming where a subclass can inherit the properties and behavior of a superclass. By using the "extends" keyword, the subclass is able to extend or inherit the superclass, allowing it to access its methods and fields. This promotes code reuse and allows for the creation of more specialized classes based on existing ones.

    Rate this question:

  • 21. 

    The Object class is not a parent class of all the classes in java by default. 

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    In Java, the Object class is indeed the parent class of all classes by default. This means that every class in Java directly or indirectly inherits from the Object class. The Object class provides basic methods and functionalities that are common to all objects in Java, such as toString(), equals(), and hashCode(). Therefore, the correct answer is False.

    Rate this question:

  • 22. 

    What is the output of this program?class increment {public static void main(String args[]){double var1 = 1 + 5; double var2 = var1 / 4;int var3 = 1 + 5;int var4 = var3 / 4;System.out.print(var2 + " " + var4); } }

    • A.

      1 1

    • B.

      0 1

    • C.

      1.5 1

    • D.

      1.5 1.0

    Correct Answer
    C. 1.5 1
    Explanation
    The program first assigns the value 1 + 5 (which is 6) to the variable var1, and then divides var1 by 4, resulting in 1.5. Next, it assigns the value 1 + 5 (which is 6) to the variable var3, and then divides var3 by 4, resulting in 1. Finally, it prints the values of var2 and var4, which are 1.5 and 1 respectively.

    Rate this question:

  • 23. 

    What is the output of this program?class increment {public static void main(String args[]) {        int g = 3;System.out.print(++g * 8);} }

    • A.

      25

    • B.

      24

    • C.

      32

    • D.

      33

    Correct Answer
    C. 32
    Explanation
    The program starts by initializing the variable "g" with the value 3. Then, it uses the pre-increment operator "++g" to increment the value of "g" by 1, resulting in "g" being equal to 4. Next, it multiplies the value of "g" (which is now 4) by 8, resulting in 32. Finally, it prints the value 32 as the output.

    Rate this question:

  • 24. 

    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

    Correct Answer
    C. UNICODE
    Explanation
    UNICODE is the correct answer because it is the coding type used for data type characters in Java. UNICODE is a universal character encoding standard that assigns a unique number to every character, regardless of the platform, program, or language. It allows Java to represent characters from all languages and scripts, making it suitable for internationalization and localization purposes. ASCII and ISO-LATIN-1 are also character encoding standards, but they have limitations in terms of the range of characters they can represent, unlike UNICODE.

    Rate this question:

  • 25. 

    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’

    Correct Answer
    C. Boolean b3 = false;
    Explanation
    The correct answer is "boolean b3 = false;". This is a valid declaration of a boolean because it assigns the value "false" to the variable b3. In Java, booleans can only have two possible values: true or false. The other options, b1 = 1, b2 = 'false', and b4 = 'true', are not valid boolean declarations because they assign values that are not of the boolean type.

    Rate this question:

  • 26. 

    What is the output of this program?class mainclass {public static void main(String args[]) {boolean var1 = true;boolean var2 = false;if (var1)System.out.println(var1);elseSystem.out.println(var2);} }

    • A.

      0

    • B.

      1

    • C.

      True

    • D.

      False

    Correct Answer
    C. True
    Explanation
    The output of this program is "true". The program initializes two boolean variables, var1 and var2, with the values true and false respectively. It then checks the condition if (var1), which evaluates to true since var1 is true. Therefore, the program executes the statement System.out.println(var1), which prints the value of var1, which is "true".

    Rate this question:

  • 27. 

    Which of these is an incorrect array declaration?

    • A.

      Int arr[] = new int[5]

    • B.

      int [] arr = new int[5]

    • C.

      Int arr[] arr = new int[5]

    • D.

      int arr[] = int [5] new

    Correct Answer
    D. int arr[] = int [5] new
  • 28. 

    Which of these is an incorrect Statement?

    • A.

      It is necessary to use new operator to initialize an array.

    • B.

      Array can be initialized using comma separated expressions surrounded by curly braces.

    • C.

      Array can be initialized when they are declared.

    • D.

      None of the mentioned

    Correct Answer
    A. It is necessary to use new operator to initialize an array.
    Explanation
    The correct answer is "It is necessary to use new operator to initialize an array." This statement is incorrect because arrays can be initialized without using the new operator. Arrays can be initialized using comma separated expressions surrounded by curly braces or they can be initialized when they are declared.

    Rate this question:

  • 29. 

    Which of these is a super class of wrappers Double & Integer?

    • A.

      Long

    • B.

      Float

    • C.

      Digits

    • D.

      Number

    Correct Answer
    D. Number
    Explanation
    The super class of wrappers Double and Integer is Number. The Number class is an abstract class in Java that is the superclass of classes representing numeric values that can be converted to primitive types. Both Double and Integer classes are part of the Number class hierarchy and inherit common methods and properties from the Number class.

    Rate this question:

  • 30. 

    Which of these keywords is used by a class to use an interface defined previously?

    • A.

      Import

    • B.

      Import

    • C.

      Implements

    • D.

      Implements

    Correct Answer
    C. Implements
    Explanation
    The keyword "implements" is used by a class to use an interface defined previously. When a class implements an interface, it is required to provide implementations for all the methods declared in that interface. This allows the class to inherit the behavior defined by the interface and also enables polymorphism, as objects of the class can be treated as objects of the interface type.

    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 14, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 16, 2017
    Quiz Created by
    Divya
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.