Java Assessment Quiz

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 Harunraja
H
Harunraja
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,604
Questions: 15 | Attempts: 1,621

SettingsSettingsSettings
Java Assessment Quiz - Quiz

How much do you know about Java? Well, soon, we will find it out when you will take this Java assessment quiz. Java is known as a high-level, class-based, object-oriented programming language. The language is designed to possess as few implementation dependencies as possible. It's one of the most used programming languages out there. We hope you like this quiz and learn more about Java as you take it. All the best, programmer!


Questions and Answers
  • 1. 

    Which is the correct option about the java interface?

    • A.

      The interface is used to achieve multiple inheritances in Java

    • B.

      The object of an interface cannot be created.

    • C.

      An interface can extend another interface.

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The correct option about the Java interface is "All of the above." This means that all the statements mentioned in the options are correct. In Java, interfaces are used to achieve multiple inheritances, meaning a class can implement multiple interfaces. An object of an interface cannot be created directly because interfaces cannot be instantiated. However, a class can implement an interface and create objects of that class. Additionally, an interface can extend another interface, allowing for the creation of a hierarchy of interfaces.

    Rate this question:

  • 2. 

    In what memory area do variable temp and variable card write in main () get stored? class CreditCard{ int num; } public class Bank { public static void main(String[] args) { int temp; CreditCard card; } }

    • A.

      Heap, Heap

    • B.

      Stack, stack

    • C.

      Heap, Stack

    • D.

      Stack, Heap

    Correct Answer
    B. Stack, stack
    Explanation
    In the given code, the variable "temp" is declared as an integer in the main() method. When a method is called, a new frame is created on the stack to store local variables. So, the variable "temp" will be stored in the stack memory area. Similarly, the variable "card" is declared as an object of the CreditCard class in the main() method. Objects in Java are reference types and the reference variable "card" will also be stored in the stack memory area. Therefore, the correct answer is "Stack, stack".

    Rate this question:

  • 3. 

    What is the output of this java program? public class MemoryJava { public static void main(String[] args) { decreaseNumberbyOne(2); } public static void decreaseNumberbyOne(int num){ if(num >= 0){ decreaseNumberbyOne(num -1); } System.out.println("Number:"+num); } }

    • A.

      -1,0,1,2

    • B.

      2,1,0,-1

    • C.

      Stack overflow

    • D.

      No output

    Correct Answer
    A. -1,0,1,2
    Explanation
    The program recursively calls the `decreaseNumberbyOne` method with `num` decremented by 1 until `num` is less than 0. Then it prints the value of `num`. Since the initial value of `num` is 2, the program will call the method with values 1, 0, and -1 before printing the value of -1. Therefore, the output will be -1, 0, 1, 2.

    Rate this question:

  • 4. 

    Which polymorphism behavior do you see in the below class? class Paint { // all methods have same name public void Color(int x) { } public void Color(int x, int y) { } public void Color(int x, int y, int z) { } }

    • A.

      Method overloading

    • B.

      Constructor overloading

    • C.

      Method overriding

    • D.

      Run time polymorphism

    Correct Answer
    A. Method overloading
    Explanation
    The given class demonstrates method overloading. Method overloading occurs when multiple methods in a class have the same name but different parameters. In this case, the "Color" method is defined three times with different numbers of parameters. This allows the class to provide different ways of coloring an object based on the number of arguments passed to the method.

    Rate this question:

  • 5. 

    __________ can be used to control the order of certain data structures and collection of objects too.

    • A.

      Serial Comparators

    • B.

      Natural Comparators

    • C.

      Comparators

    • D.

      All of the above

    Correct Answer
    C. Comparators
    Explanation
    Comparators can be used to control the order of certain data structures and collections of objects. Comparators provide a way to define custom ordering for objects, allowing for sorting and ordering based on specific criteria. By implementing the Comparator interface, developers can define their own comparison logic and apply it to various data structures and collections, giving them control over the ordering of the elements. Therefore, the correct answer is "Comparators".

    Rate this question:

  • 6. 

    In the below java code, whose “Car” will be called? class Father { public void car() { System.out.println("Father's Car"); } } class Son extends Father { public void car() { System.out.println("Son's Car"); } } public class Sample { public static void main(String[] args) { Son john = new Son(); john.car(); } }

    • A.

      Father’s Car

    • B.

      Son’s Car

    • C.

      There is an ambiguity, so no one's Car

    • D.

      Compiler Error

    Correct Answer
    B. Son’s Car
    Explanation
    In this Java code, the method `car()` is overridden in the `Son` class, which means that when the `car()` method is called on the object `john`, it will execute the code inside the `car()` method in the `Son` class. Therefore, the output will be "Son's Car".

    Rate this question:

  • 7. 

    What exception can occur in the below java program if we access 5 element in the array that does not exist? public class TException { public static void main(String[] args) { try { int a[] = { 5, 10, 15, 20 }; System.out.println("Element :" + a[4]); } finally{} } }

    • A.

      ArrayIndexOutOfBoundsException

    • B.

      ArithmeticException

    • C.

      NullPointerException

    • D.

      None

    Correct Answer
    A. ArrayIndexOutOfBoundsException
    Explanation
    If we try to access the 5th element in the array using the index 4 (a[4]), it will result in an ArrayIndexOutOfBoundsException. This exception occurs when we try to access an index that is outside the bounds of the array. In this case, the array has only 4 elements (indexes 0, 1, 2, and 3), so trying to access the 5th element will throw this exception.

    Rate this question:

  • 8. 

    After the following code fragment, what is the value in fname? String str; int fname; str = “Foolish boy.”; fname = str.indexOf(“fool”);

    • A.

      0

    • B.

      2

    • C.

      -1

    • D.

      4

    Correct Answer
    C. -1
    Explanation
    The value in fname is -1 because the method indexOf() returns the index of the first occurrence of the specified substring in the given string. In this case, the substring "fool" is not found in the string "Foolish boy." so the method returns -1.

    Rate this question:

  • 9. 

    Direct subclass of Throwable in Java

    • A.

      Exception

    • B.

      Error

    • C.

      Both A & C

    • D.

      None

    Correct Answer
    C. Both A & C
    Explanation
    Both A and C are correct because in Java, both Exception and Error are direct subclasses of Throwable. This means that both Exception and Error inherit directly from the Throwable class, making them direct subclasses.

    Rate this question:

  • 10. 

    Given the following code snippet; int salaries[]; int index = 0; salaries = new int salaries[4]; while (index < 4) { salaries[index] =  10000; index++; } What is the value of salaries[3]?

    • A.

      40000

    • B.

      50000

    • C.

      15000

    • D.

      10000

    Correct Answer
    D. 10000
    Explanation
    The code snippet initializes an array called "salaries" with a size of 4. Then, it enters a while loop that iterates as long as the "index" variable is less than 4. Inside the loop, it assigns the value of 10000 to each element of the "salaries" array, starting from index 0 and incrementing the index by 1 each time. Therefore, the value of salaries[3] is 10000.

    Rate this question:

  • 11. 

    Assume that the value 3929.92 is of type float. How to assign this value after declaring the variable interest of type float?

    • A.

       interest = 3929.92

    • B.

      Interest = (Float)3929.92

    • C.

      Interest = 3929.92(float)

    • D.

      Interest = 3929.92f

    Correct Answer
    D. Interest = 3929.92f
    Explanation
    To assign the value 3929.92 to the variable interest of type float, we use the syntax interest = 3929.92f. The "f" at the end of the number indicates that it is a float value.

    Rate this question:

  • 12. 

    What is the data type for the number 9.6352?

    • A.

       float

    • B.

      Double

    • C.

      Float

    • D.

      Double

    Correct Answer
    B. Double
    Explanation
    The data type for the number 9.6352 is double. This is because double is a data type that can hold decimal values with a higher precision compared to float.

    Rate this question:

  • 13. 

    In a class definition, the special method provided to be called to create an instance of that class is known as a/an

    • A.

      Interpreter 

    • B.

      Destructor 

    • C.

      Constructor 

    • D.

      Object 

    • E.

      Compiler

    Correct Answer
    C. Constructor 
    Explanation
    In a class definition, the special method provided to be called to create an instance of that class is known as a constructor. Constructors are used to initialize the object's state and allocate memory for the object. They are typically defined with the same name as the class and are automatically called when an object of the class is created.

    Rate this question:

  • 14. 

     What is the meaning of the return data type void?

    • A.

      An empty memory space is returned so that the developers can utilize it.

    • B.

      Void returns no data type.

    • C.

      Void is not supported in Java.

    • D.

       None of the above.

    Correct Answer
    B. Void returns no data type.
    Explanation
    The return data type "void" is used in programming languages to indicate that a function or method does not return any value. It is used when the function or method is intended to perform a task or operation without producing a result that needs to be stored or used elsewhere in the program. In other words, when a function or method has a return type of "void", it means that it does not return any data or memory space for the developers to utilize.

    Rate this question:

  • 15. 

     Java object oriented programming concepts is/are

    • A.

      Encapsulation

    • B.

      Inheritance

    • C.

      Polymorphism

    • D.

      All of the above.

    Correct Answer
    D. All of the above.
    Explanation
    The correct answer is "All of the above" because Java object-oriented programming concepts include encapsulation, inheritance, and polymorphism. Encapsulation refers to the bundling of data and methods together into a single unit, known as a class. Inheritance allows classes to inherit properties and methods from other classes, creating a hierarchy of classes. Polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling flexibility and code reusability. Therefore, all three concepts are fundamental to Java's object-oriented programming paradigm.

    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
  • Aug 24, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 05, 2020
    Quiz Created by
    Harunraja
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.