Online Test On OOP Using Java

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 Maheshjangid
M
Maheshjangid
Community Contributor
Quizzes Created: 2 | Total Attempts: 526
Questions: 71 | Attempts: 405

SettingsSettingsSettings
Java Quizzes & Trivia

No Negative marking
Attempt questions as many you can


Questions and Answers
  • 1. 

    Following code will result in: int a = 3.5;

    • A.

      Compilation error

    • B.

      Runtime error

    Correct Answer
    A. Compilation error
    Explanation
    The given code will result in a compilation error because it is trying to assign a floating-point value (3.5) to an integer variable (a). In Java, this is not allowed without explicit type casting.

    Rate this question:

  • 2. 

    Following code will result in: int a1 = 5; double a2 = (float)a1;

    • A.

      Runtime error

    • B.

      No errors

    Correct Answer
    B. No errors
    Explanation
    The code will not result in any errors because it is a valid type casting operation. The value of the integer variable a1 is being explicitly casted to a float type and then assigned to the double variable a2. Since the float type can be safely promoted to a double type without any loss of precision, the code will execute without any errors.

    Rate this question:

  • 3. 

     Following code will result in: int a = 9/0;

    • A.

      Compilation error: Divisions must be in a try block.

    • B.

      Runtime Exception

    Correct Answer
    B. Runtime Exception
    Explanation
    The given code will result in a runtime exception because it is trying to divide 9 by 0, which is not a valid operation in mathematics. This will throw an ArithmeticException at runtime.

    Rate this question:

  • 4. 

    Following code will result in: float a = 9/0

    • A.

      Compilation error: DivideByZeroException

    • B.

      Runtime Exception

    Correct Answer
    B. Runtime Exception
    Explanation
    The given code will result in a runtime exception because it attempts to divide the number 9 by 0. Division by zero is not defined in mathematics and is considered an error in programming. When this code is executed, it will throw a runtime exception specifically for dividing by zero, causing the program to terminate abruptly.

    Rate this question:

  • 5. 

    A class can be transient

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    A class cannot be transient. Transient is a keyword in programming languages like Java that is used to indicate that a variable should not be serialized, meaning it should not be saved or restored when the object is serialized or deserialized. However, the transient keyword cannot be applied to a class itself. It can only be applied to variables within a class. Therefore, the statement "A class can be transient" is false.

    Rate this question:

  • 6. 

    Following code will result in: class A { int b = 1; public static void main(String [] args) { System.out.println("b is " + b); }}

    • A.

      Compilation error

    • B.

      Runtime Error

    Correct Answer
    A. Compilation error
    Explanation
    The given code will result in a compilation error because the variable "b" is declared as an instance variable within the class A, but it is being accessed in the static main method. Since the main method is a static method, it does not have access to instance variables directly. To access the variable "b" in the main method, it either needs to be declared as a static variable or an instance of class A needs to be created to access the instance variable.

    Rate this question:

  • 7. 

    Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}

    • A.

      Compile error

    • B.

      No error

    Correct Answer
    A. Compile error
    Explanation
    The code will result in a compile error because class B extends class A, but class A does not have a constructor that takes no arguments. Therefore, when trying to create a new instance of class B in the main method of class A, the compiler will throw an error because it cannot find a suitable constructor in class A to instantiate class B.

    Rate this question:

  • 8. 

    Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}

    • A.

      Runtime Exception

    • B.

      No errors

    Correct Answer
    B. No errors
    Explanation
    The code will not result in any errors because class B extends class A, so it is valid to assign an instance of class B to a variable of type A. The code will compile and run without any issues.

    Rate this question:

  • 9. 

    Methods that are marked protected can be called in any subclass of that class.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Protected methods in a class can be accessed by any subclass of that class. This means that if a method is marked as protected in a superclass, it can be called and used in any subclass that extends that superclass. This allows for inheritance and the ability to override or modify the behavior of the protected method in the subclass. Therefore, the statement "Methods that are marked protected can be called in any subclass of that class" is true.

    Rate this question:

  • 10. 

    An abstract class can have non-abstract methods

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    An abstract class can have non-abstract methods because an abstract class is a class that cannot be instantiated and is meant to be extended by other classes. It can contain both abstract and non-abstract methods. Non-abstract methods in an abstract class can have a complete implementation and can be directly called by the subclasses that inherit from the abstract class. This allows the abstract class to provide common functionality to its subclasses while still allowing the subclasses to implement their own unique functionality.

    Rate this question:

  • 11. 

    Java keywords are written in lowercase as well as uppercase

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Java keywords are written in lowercase as well as uppercase. This statement is true because Java is case-sensitive, meaning that lowercase and uppercase letters are treated as distinct characters. Keywords in Java, such as "public," "class," and "static," are predefined and have specific meanings in the language. These keywords must be written in lowercase letters to be recognized by the Java compiler. However, Java also allows developers to use uppercase letters for keywords, although it is not a common practice.

    Rate this question:

  • 12. 

    What is an instanceof

    • A.

      A methods in object

    • B.

      An operator and keyword

    Correct Answer
    B. An operator and keyword
    Explanation
    The correct answer is "An operator and keyword." The instanceof operator is used to check whether an object belongs to a particular class or implements a particular interface. It returns true if the object is an instance of the specified class or interface, and false otherwise. Therefore, instanceof is both an operator and a keyword in Java.

    Rate this question:

  • 13. 

    Primitive datatypes are allocated on a stack

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Primitive datatypes are allocated on a stack. This means that when a primitive datatype is declared, memory is allocated for it on the stack. The stack is a region of memory that is used for temporary storage of variables. When a variable goes out of scope, the memory allocated for it on the stack is automatically released. This is different from objects, which are allocated on the heap and require manual memory management.

    Rate this question:

  • 14. 

    Can you compare a boolean to an integer?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
    Explanation
    A boolean is a data type that represents two possible values: true or false. An integer, on the other hand, is a data type that represents whole numbers. These two data types are not compatible for direct comparison because they represent different concepts. In most programming languages, attempting to compare a boolean to an integer would result in a type mismatch error. Therefore, the correct answer is "No".

    Rate this question:

  • 15. 

    If class A implements an interface does it need to implement all methods of that interface?

    • A.

      Yes, always

    • B.

      No, not when A is abstract

    Correct Answer
    B. No, not when A is abstract
    Explanation
    When a class A implements an interface, it is generally required to implement all the methods of that interface. However, if class A is declared as abstract, it is not mandatory to implement all the methods of the interface. This is because abstract classes can have abstract methods, which do not require implementation in the abstract class itself. The responsibility of implementing these abstract methods is passed on to the concrete subclasses of the abstract class. Therefore, when class A is abstract, it is not necessary to implement all the methods of the interface in class A.

    Rate this question:

  • 16. 

    Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?

    • A.

      True

    • B.

      FALSE

    Correct Answer
    B. FALSE
    Explanation
    When comparing two Integer objects using the "==" operator, it checks if the two objects refer to the same memory location. In this case, even though the values of a and b are both 2, they are separate objects created using the "new" keyword. Therefore, they will have different memory locations, resulting in the comparison returning false.

    Rate this question:

  • 17. 

    The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces of code.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The methods wait(), notify(), and notifyAll() in the Object class are used for inter-thread communication and synchronization. They are designed to be called from synchronized blocks or methods. When a thread calls wait(), it releases the lock it holds and enters a waiting state until another thread notifies it. Similarly, notify() and notifyAll() are used to wake up threads that are waiting. To ensure proper synchronization and avoid race conditions, these methods should only be called within synchronized code blocks or methods. Therefore, the statement is true.

    Rate this question:

  • 18. 

    Inner classes can be defined within methods

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Inner classes can be defined within methods in Java. An inner class is a class that is defined inside another class. It can be defined within a method, allowing it to have access to the variables and methods of the enclosing method. This can be useful in situations where a class is only needed within a specific method and does not need to be accessed outside of it. By defining the inner class within the method, it keeps the code more organized and encapsulated.

    Rate this question:

  • 19. 

    Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The explanation for the given correct answer is that the "synchronized" keyword in Java is used to ensure that only one thread can access a block of code or an object at a time. When a thread encounters a synchronized block or method, it grabs the object lock associated with that block or method and other threads have to wait until the lock is released. This helps in preventing multiple threads from accessing and modifying shared data simultaneously, thereby ensuring thread safety and avoiding race conditions. Therefore, the statement that "synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution" is true.

    Rate this question:

  • 20. 

    The default statement of a switch is always executed

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The default statement of a switch is not always executed. The default statement is only executed when none of the cases match the value being tested. If a case matches the value, the corresponding statement is executed and the program exits the switch statement. If there is no default statement, the program simply continues to the next line of code after the switch statement. Therefore, the correct answer is False.

    Rate this question:

  • 21. 

    How can you prevent a member variable from becoming serialized?

    • A.

      By marking it volatile

    • B.

      By marking it transient

    Correct Answer
    B. By marking it transient
    Explanation
    By marking a member variable as transient, it indicates to the serialization process that this variable should not be serialized. This is useful when there are certain variables that should not be saved or transmitted when an object is being serialized. The transient keyword allows for control over which variables are included in the serialization process, preventing the member variable from being serialized. The volatile keyword, on the other hand, is used for ensuring that the value of a variable is always read from the main memory and not from a cache, and it does not have any direct relation to serialization.

    Rate this question:

  • 22. 

    What is Java (in regard to Computer Science) ?

    • A.

       A type of coffee

    • B.

      AN OBJECT-ORIENTED PROGRAMMING LANGUAGE

    Correct Answer
    B. AN OBJECT-ORIENTED PROGRAMMING LANGUAGE
    Explanation
    Java is an object-oriented programming language widely used in computer science. It was developed by Sun Microsystems and is known for its platform independence, meaning that Java programs can run on any device that has a Java Virtual Machine. Java is popular for its simplicity, robustness, and security features. It is used to develop a wide range of applications, including web and mobile applications, enterprise software, and embedded systems. Java's object-oriented nature allows for the creation of reusable code and promotes modular and scalable software development.

    Rate this question:

  • 23. 

    WHAT IS AN APPLET?

    • A.

      A JAVA PROGRAM THAT IS RUN THROUGH A WEB BROWSER

    • B.

       A type of coffee

    Correct Answer
    A. A JAVA PROGRAM THAT IS RUN THROUGH A WEB BROWSER
    Explanation
    An applet is a Java program that is designed to be executed within a web browser. It is a small application that is typically embedded in a web page and runs on the client-side. Applets are used to provide dynamic and interactive content on websites. They can perform various tasks such as animations, data processing, and user input handling. By running within a web browser, applets can be easily accessed and executed by users without the need for additional installations or configurations.

    Rate this question:

  • 24. 

    Java runs on _______.

    • A.

       Windows

    • B.

      All of the Above

    • C.

       Unix/Linux

    Correct Answer
    B. All of the Above
    Explanation
    Java is a platform-independent programming language, which means it can run on multiple operating systems including Windows, Unix/Linux, and others. Therefore, the correct answer is "All of the Above" as Java can run on all the mentioned operating systems.

    Rate this question:

  • 25. 

    Why can't the whole program just consist of the one line that does the painting ?

    • A.

      In Java, to create an applet, you can't call on functions without defining a class to call them.

    • B.

      The drawString function is not defined without the "import" statements at the top.

    • C.

       All of the above.

    Correct Answer
    C.  All of the above.
    Explanation
    The correct answer is "All of the above." This is because all three statements provided are valid explanations for why the whole program cannot just consist of the one line that does the painting. In Java, to create an applet, you need to define a class to call functions. Additionally, the drawString function is not defined without the "import" statements at the top. Therefore, all three statements contribute to the explanation of why the whole program cannot just consist of the one line that does the painting.

    Rate this question:

  • 26. 

    What's the difference between an Applet and an application ?

    • A.

      Applets can paint words, applications cannot.

    • B.

       Applets are run over the web.

    Correct Answer
    B.  Applets are run over the web.
    Explanation
    An applet is a small program that is designed to be run within another application or through a web browser. It is typically used to enhance the functionality of a website. On the other hand, an application is a standalone program that is installed and run directly on a computer or device. The key difference between an applet and an application is that applets are specifically designed to be run over the web, while applications are not limited to web-based environments. Therefore, the correct answer is that applets are run over the web.

    Rate this question:

  • 27. 

    What is the main function of any variable ?

    • A.

       To add numbers together

    • B.

       To keep track of data in the memory of the computer

    Correct Answer
    B.  To keep track of data in the memory of the computer
    Explanation
    The main function of any variable is to keep track of data in the memory of the computer. Variables are used to store and manipulate data in computer programs. They provide a way to assign values to a specific location in memory, which can then be accessed and modified throughout the program. By using variables, programmers can store and retrieve data as needed, making it an essential aspect of programming.

    Rate this question:

  • 28. 

    What is the proper way to declare a variable ?

    • A.

      VariableName variableType;

    • B.

      VariableType variableName;

    Correct Answer
    B. VariableType variableName;
    Explanation
    The proper way to declare a variable is by specifying the variable type followed by the variable name. This allows the compiler to allocate the appropriate amount of memory for the variable based on its type.

    Rate this question:

  • 29. 

     Booleans are _______.

    • A.

       True or False

    • B.

       Single characters

    Correct Answer
    A.  True or False
    Explanation
    Booleans are data types that can have one of two values: true or false. They are used to represent logical values and are commonly used in programming to make decisions and control the flow of a program.

    Rate this question:

  • 30. 

    The following statements make “length” be what number ?

    • A.

       5

    • B.

      6

    Correct Answer
    A.  5
    Explanation
    The question is asking for the number that makes "length" equal to it. The given options are 5 and 6. Since the answer is 5, it means that "length" is equal to 5.

    Rate this question:

  • 31. 

    What is an assignment statement ?

    • A.

      Assigning a name to a variable

    • B.

      Assigning a value to a variable

    Correct Answer
    B. Assigning a value to a variable
    Explanation
    An assignment statement is a statement that assigns a value to a variable. It is used to store a value in a variable so that it can be used later in the program. By assigning a value to a variable, we are giving it a specific data value that can be manipulated or used in calculations or comparisons. This allows us to store and manipulate data in a program, making it an essential concept in programming.

    Rate this question:

  • 32. 

    What will be the value of “num” after the following statements?

    • A.

      1

    • B.

      12

    Correct Answer
    B. 12
    Explanation
    The value of "num" will be 12 because the given statements are "1" and "12", which means that the value of "num" is being assigned as 12 in the second statement.

    Rate this question:

  • 33. 

     If you want your conditional to depend on two conditions BOTH being true, what is the proper notation to put between the two Boolean statements ?

    • A.

      &&

    • B.

      !!

    Correct Answer
    A. &&
    Explanation
    The proper notation to put between two Boolean statements when you want your conditional to depend on both conditions being true is "&&". This is the logical operator for "and" in many programming languages. It evaluates to true only if both conditions are true, otherwise, it evaluates to false.

    Rate this question:

  • 34. 

    Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4 ?

    • A.

       if ((x < 3) || (y > = 4))

    • B.

       if ((x > 3) || (y < = 4))

    Correct Answer
    A.  if ((x < 3) || (y > = 4))
    Explanation
    The correct answer is "if ((x < 3) || (y >= 4))". This means that for the conditional statement to be true, either x must be less than 3 or y must be greater than or equal to 4.

    Rate this question:

  • 35. 

     What is a loop ?

    • A.

       A new type of Applet

    • B.

       A segment of code to be run a specified amount of times

    Correct Answer
    B.  A segment of code to be run a specified amount of times
    Explanation
    A loop is a segment of code that is repeated a specified number of times. It allows for the execution of a certain block of code repeatedly until a specific condition is met. Loops are used to automate repetitive tasks and make the code more efficient by reducing the need for duplicate code. They are an essential part of programming and are commonly used in various programming languages to iterate through arrays, perform calculations, and execute a specific set of instructions multiple times.

    Rate this question:

  • 36. 

    What is essential in making sure that your loop is not infinite ?

    • A.

      That there is a Boolean statement somewhere in your code

    • B.

      That your Boolean statement will at some point be false

    Correct Answer
    B. That your Boolean statement will at some point be false
    Explanation
    In order to ensure that a loop is not infinite, it is essential to have a Boolean statement somewhere in the code that will eventually be false. This allows the loop to terminate and prevents it from running indefinitely. Without a condition that can evaluate to false, the loop will continue to repeat indefinitely, resulting in an infinite loop.

    Rate this question:

  • 37. 

    Which is NOT a section of all types of loops ?

    • A.

       Test statement

    • B.

       The word "while"

    Correct Answer
    B.  The word "while"
    Explanation
    The word "while" is not a section of all types of loops. While loops have a test condition that is evaluated before each iteration, and if the condition is true, the loop body is executed. Other types of loops, such as for loops and do-while loops, have different sections, such as initialization, increment/decrement, and loop body. Therefore, the word "while" does not apply to all types of loops.

    Rate this question:

  • 38. 

    In a ‘for’ loop, what section of the loop is not included in the parentheses after “for” ?

    • A.

       Loop Body

    • B.

       Initialization

    Correct Answer
    A.  Loop Body
    Explanation
    In a 'for' loop, the section of the loop that is not included in the parentheses after 'for' is the Loop Body. The loop body contains the code that is executed repeatedly until the loop condition is false. The initialization section, on the other hand, is included in the parentheses after 'for' and is responsible for initializing the loop control variable.

    Rate this question:

  • 39. 

    What is a function in terms of Computer Science ?

    • A.

       A group of code lines that performs a specific task

    • B.

       Something that contains an ‘init’

    Correct Answer
    A.  A group of code lines that performs a specific task
    Explanation
    A function in computer science is a group of code lines that performs a specific task. It is a way to organize and modularize code by breaking it down into smaller, reusable units. Functions can be called and executed multiple times throughout a program, making it easier to maintain and debug code. They can also accept input parameters and return output values, allowing for flexibility and reusability in programming.

    Rate this question:

  • 40. 

    What does AWT stands for ?

    • A.

       Abstract window Toolkit

    • B.

       Adjust Window Toolkit

    Correct Answer
    A.  Abstract window Toolkit
    Explanation
    AWT stands for Abstract Window Toolkit. It is a set of application programming interfaces (APIs) provided by Java for creating graphical user interfaces (GUIs) for Java programs. AWT provides a platform-independent way of creating windows, buttons, menus, and other GUI components. It is a part of the Java Foundation Classes (JFC) and is used to develop GUI-based applications in Java.

    Rate this question:

  • 41. 

    11.1 Q1: Which of the following statements is false?

    • A.

      A. Exception handling enables programmers to write robust and fault-tolerant programs.

    • B.

      B. Exception handling can catch but not resolve exceptions.

    • C.

      C. Exception handling can resolve exceptions.

    • D.

      D. All of the above are true.

    Correct Answer
    B. B. Exception handling can catch but not resolve exceptions.
    Explanation
    Exception handling enables programmers to write robust and fault-tolerant programs by providing a mechanism to catch and handle exceptions. It allows programmers to anticipate and handle potential errors or exceptional situations that may occur during program execution. However, exception handling alone cannot resolve exceptions, as resolving exceptions typically involves taking appropriate actions to correct the error or exceptional situation that caused the exception. Therefore, statement b is false.

    Rate this question:

  • 42. 

    11.2 Q1: Intermixing program and error-handling logic:

    • A.

      A. increases a program’s performance, because the program does not need to perform tests to determine whether a task executed correctly and the next task can be performed.

    • B.

      B. should be used in place of exception handling where possible.

    • C.

      C. can degrade a program’s performance, because the program must perform (potentially frequent) tests to determine whether a task executed correctly and the next task can be performed.

    • D.

      D. None of the above.

    Correct Answer
    C. C. can degrade a program’s performance, because the program must perform (potentially frequent) tests to determine whether a task executed correctly and the next task can be performed.
    Explanation
    Intermixing program and error-handling logic can degrade a program's performance because it requires the program to perform tests to determine if a task executed correctly and if the next task can be performed. This can result in potentially frequent tests, which can slow down the program's execution. Therefore, option c is the correct answer as it accurately describes the impact of intermixing program and error-handling logic on a program's performance.

    Rate this question:

  • 43. 

    11.3 Q2: Which of the following is not included in an exception’s stack trace?

    • A.

      A. A descriptive message for the exception.

    • B.

      B. The method-call stack at the time the exception occurred.

    • C.

      C. The name of the exception.

    • D.

      D. Instructions on handling the exception.

    Correct Answer
    D. D. Instructions on handling the exception.
    Explanation
    The stack trace of an exception typically includes information about the method-call stack at the time the exception occurred, the name of the exception, and a descriptive message for the exception. However, it does not include instructions on handling the exception. The stack trace is mainly used for debugging purposes and helps identify the sequence of method calls that led to the exception. Instructions on handling the exception are typically provided in the code where the exception is caught and handled.

    Rate this question:

  • 44. 

    11.3 Q3: Which of the following statements regarding the throw point of an exception is false?

    • A.

      A. It specifies the point at which the exception must be handled.

    • B.

      B. It is the initial point at which the exception occurs.

    • C.

      C. It is specified as the top row of the method-call stack at the time the exception occurred.

    • D.

      D. All of the above statements are true.

    Correct Answer
    A. A. It specifies the point at which the exception must be handled.
    Explanation
    The throw point of an exception refers to the initial point at which the exception occurs, not the point at which it must be handled. The throw point is the location in the code where the exception is thrown, and it is up to the programmer to decide where and how to handle the exception. Therefore, statement a is false.

    Rate this question:

  • 45. 

    Which is the valid declarations within an interface definition?

    • A.

      Public double methoda();

    • B.

      Public final double methoda();

    • C.

      Static void methoda(double d1)

    • D.

      All

    Correct Answer
    A. Public double methoda();
    Explanation
    Option A is correct. A public access modifier is acceptable. The method prototypes in an interface are all abstract by virtue of their declaration, and should not be declared abstract.
    Option B is wrong. The final modifier means that this method cannot be constructed in a subclass. A final method cannot be abstract.
    Option C is wrong. static is concerned with the class and not an instance.

    Rate this question:

  • 46. 

    Which is right way to creating an array of integer in java?

    • A.

      Int javaArray = new int[10];

    • B.

      Int avaArray new = myArray[ ];

    • C.

      Int[] javaArray = new int[10];

    • D.

      None

    Correct Answer
    C. Int[] javaArray = new int[10];
    Explanation
    The correct way to create an array of integers in Java is by using the syntax "int[] javaArray = new int[10];". This creates an array named "javaArray" with a length of 10, capable of storing integer values. The other options provided in the question are incorrect. "int javaArray = new int[10];" is incorrect because it declares a single integer variable instead of an array. "int avaArray new = myArray[ ];" is incorrect because it contains syntax errors and does not create an array. "none" is also incorrect because there is a correct way to create an array in Java.

    Rate this question:

  • 47. 

    Which keyword is used to inherit class?

    • A.

      Inherit

    • B.

      Extends

    • C.

      Inheritance

    • D.

      Extend

    Correct Answer
    B. Extends
    Explanation
    The keyword "extends" is used to inherit a class in object-oriented programming. When a class extends another class, it means that the subclass inherits all the properties and methods of the superclass. This allows the subclass to reuse code from the superclass and also add its own unique functionality. Therefore, "extends" is the correct keyword to indicate inheritance in Java and other similar languages.

    Rate this question:

  • 48. 

    Which of the java classes that cannot be subclassed?

    • A.

      Abstract class

    • B.

      Public class

    • C.

      Final class

    • D.

      None of above

    Correct Answer
    C. Final class
    Explanation
    A final class in Java cannot be subclassed because it is marked with the "final" keyword, which indicates that it cannot be extended. This is often done to prevent further modification or extension of the class, ensuring that its behavior remains consistent and preventing any unintended changes that may break its functionality. Therefore, a final class is considered to be a complete and final implementation that cannot be altered or extended by any other class.

    Rate this question:

  • 49. 

    An abstract class should have methods all declared abstract?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
    Explanation
    An abstract class can have both abstract and non-abstract methods. It is not necessary for all methods in an abstract class to be declared as abstract. Abstract methods are those that do not have any implementation and must be overridden by the subclasses. Non-abstract methods in an abstract class can have their own implementation and can be used by the subclasses without any modification. Therefore, an abstract class should not have all methods declared as abstract.

    Rate this question:

  • 50. 

     The finalize() method present in Object class is called just prior to

    • A.

      An object, variable or method goes out of scope.

    • B.

      An object or variable goes out of scope.

    • C.

      A variable goes out of scope

    • D.

      Before garbage collection

    Correct Answer
    D. Before garbage collection
    Explanation
    The finalize() method present in the Object class is called before garbage collection. Garbage collection is the process of automatically reclaiming memory that is no longer in use by objects in a program. When an object or variable goes out of scope, meaning it is no longer accessible or needed, it becomes eligible for garbage collection. The finalize() method allows an object to perform any necessary cleanup operations before it is garbage collected. Therefore, the correct answer is "before garbage collection."

    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 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 21, 2014
    Quiz Created by
    Maheshjangid
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.