Online Test On OOP Using Java

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Maheshjangid
M
Maheshjangid
Community Contributor
Quizzes Created: 2 | Total Attempts: 655
| Attempts: 513 | Questions: 71
Please wait...
Question 1 / 71
0 %
0/100
Score 0/100
1. Java runs on _______.

Explanation

Java is a platform-independent language, which means it can run on multiple operating systems including Windows, Unix/Linux, and Mac. The Java Virtual Machine (JVM) allows Java programs to be executed on different platforms without the need for recompilation. Therefore, the correct answer is "All of the Above" as Java can run on all the mentioned operating systems.

Submit
Please wait...
About This Quiz
Online Test On OOP Using Java - Quiz

No Negative marking
Attempt questions as many you can

2.  What is a loop ?

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.

Submit
3. WHAT IS AN APPLET?

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.

Submit
4. Java runs on _______.

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.

Submit
5. What is Java (in regard to Computer Science) ?

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.

Submit
6.  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 ?

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.

Submit
7. What is a function in terms of Computer Science ?

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.

Submit
8. 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 ?

Explanation

The proper notation to put between two Boolean statements if you want your conditional to depend on both conditions being true is "&&". This is the logical AND operator in many programming languages. It returns true only if both conditions on either side of it are true.

Submit
9.  Booleans are _______.

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.

Submit
10. What is an assignment statement ?

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.

Submit
11. 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 ?

Explanation

The correct answer is "if ((x = 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.

Submit
12. What is the main function of any variable ?

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.

Submit
13. 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 ?

Explanation

The correct answer is "if ((x = 4))". This means that in order for the conditional statement to be true, either x must be less than 3 or y must be greater than or equal to 4. The "||" operator represents logical OR, so either condition can be true for the entire statement to be true.

Submit
14. What is the proper way to declare a variable ?

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.

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

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.

Submit
16. What's the difference between an Applet and an application ?

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.

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

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.

Submit
18. Which keyword is used to inherit class?

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.

Submit
19. What is an Applet ?

Explanation

An applet is a Java program that is designed to run within a web browser. It is embedded within an HTML page and is executed on the client-side, meaning it runs on the user's computer rather than on a server. Applets are used to create interactive and dynamic content on web pages, such as animations, games, or data visualizations. They have limited access to system resources and are subject to certain security restrictions to ensure the safety of the user's computer.

Submit
20. What's the difference between an Applet and an application ?

Explanation

Applets are a type of program that can be run within a web browser, whereas applications are standalone programs that are installed and run on a computer's operating system. This means that applets can be accessed and executed through a web page, while applications require installation and can be run independently. Therefore, the correct answer is that applets are run over the web.

Submit
21. Following code will result in: int a = 3.5;

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.

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

Explanation

The explanation for the given correct answer is that the "synchronized" keyword in Java is used to achieve thread synchronization. When a method or a block of code is declared as synchronized, it means that only one thread can access that method or block at a time. This ensures that the shared resources are accessed in a mutually exclusive manner, preventing any data inconsistencies or race conditions. Therefore, the statement that synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution is true.

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

Explanation

The methods wait(), notify(), and notifyAll() in the Object class need to be called from synchronized pieces of code because they are used for inter-thread communication and coordination. When a thread calls the wait() method, it releases the lock on the object and waits for another thread to notify it. Similarly, the notify() and notifyAll() methods are used to wake up waiting threads. To ensure proper synchronization and avoid race conditions, these methods should be called within synchronized blocks or methods.

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

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.

Submit
25. The following prototype shows that a Cylinder subclass is derived from a superclass called Circle

Explanation

The correct answer is "class Cylinder extends Circle". This means that the class "Cylinder" is derived from the superclass "Circle". In object-oriented programming, inheritance is used to create a subclass that inherits the properties and methods of a superclass. In this case, the subclass "Cylinder" is inheriting from the superclass "Circle", which suggests that a cylinder is a type of circle with additional properties or methods specific to cylinders.

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

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.

Submit
27. Primitive datatypes are allocated on a stack

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.

Submit
28. What does AWT stands for ?

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.

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

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.

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

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.

Submit
31. An abstract class can have non-abstract methods

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.

Submit
32. Can you compare a boolean to an integer?

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".

Submit
33. Which of the java classes that cannot be subclassed?

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.

Submit
34. With inheritance, a derived subclass object can directly access any

Explanation

Inheritance allows a derived subclass object to directly access any public superclass member. Additionally, if the subclass is in the same package as the superclass, it can also access protected subclass members. However, private superclass members cannot be accessed by the subclass object. Therefore, the correct answer is "public superclass member (and protected subclass members if it's in the same package)".

Submit
35. You can construct a new Color by providing 3 integers that represent ___________, ___________, and ____________ colors

Explanation

The correct answer is Red, Green, Blue. This is because these three integers represent the primary colors in the RGB color model. In this model, different intensities of red, green, and blue are combined to create a wide range of colors. By providing these three integers, you can create a new Color object with a specific RGB color.

Submit
36. How can you prevent a member variable from becoming serialized?

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.

Submit
37. In a 'for' loop, what section of the loop is not included in the parentheses after "for" ?

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.

Submit
38. An abstract class should have methods all declared abstract?

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.

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

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.

Submit
40. In which memory area of JVM objects will be created?

Explanation

Objects in Java are created in the Heap memory area of the JVM. The Heap memory is a region of memory that is shared among all threads and is used for dynamic memory allocation. When an object is created using the "new" keyword, memory is allocated in the Heap for that object. The Heap memory is managed by the garbage collector, which automatically frees up memory for objects that are no longer in use.

Submit
41. Inner classes can be defined within methods

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.

Submit
42. Inner classes can be defined within methods.

Explanation

Inner classes can be defined within methods. This means that a class can be declared inside a method of another class. This is useful when the inner class is only needed within that specific method and does not need to be accessed or used outside of it. By defining an inner class within a method, it allows for better encapsulation and organization of code.

Submit
43. How can you prevent a member variable from becoming serialized?

Explanation

A transient variable is a variable that may not be serialized.

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

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.

Submit
45. The applet can  received the parameter values using the method ___________

Explanation

The applet can receive the parameter values using the method getParameter(). This method allows the applet to retrieve the values of parameters that are passed to it. By using getParameter(), the applet can access and use these parameter values for various purposes within its functionality.

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

Explanation

The given code will result in a compile error because the line "B b = new A();" is trying to create an object of class A and assign it to a variable of type B. Since B is a subclass of A, it is valid to assign an object of type B to a variable of type A, but the reverse is not true. Therefore, the code will not compile.

Submit
47. The default statement of a switch is always executed

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.

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

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.

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

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.

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

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.

Submit
51. Given the code. What is the result after the class TryMe execution? class A {     public void doA() {         B b = new B();         b.dobB();         System.out.print("doA");     } }   class B {     public void dobB() {         C c = new C();         c.doC();         System.out.print("doB");     } }   class C {     public void doC() {         if (true)             throw new NullPointerException();         System.out.print("doC");     } }   public class TryMe {       public static void main(String args[]) {         try {             A a = new A();             a.doA();         } catch (Exception ex) {             System.out.print("error");         }     } }

Explanation

The code throws a NullPointerException in the doC() method of class C. Since the exception is not caught within the doC() method, it propagates up the call stack to the main method. In the main method, the exception is caught in the catch block and "error" is printed. Therefore, the result after the class TryMe execution is "error" is printed.

Submit
52. Which is NOT a section of all types of loops ?

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.

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

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.

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

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.

Submit
55. Given the code. What is the result if NullPointerException occurs at line 2? 1.      try { 2.          //some code goes here 3.      } 4.      catch (NullPointerException ne) { 5.          System.out.print("1 "); 6.      } 7.      catch (RuntimeException re) { 8.          System.out.print("2 "); 9.      } 10.     finally { 11.         System.out.print("3"); 12.     }

Explanation

If a NullPointerException occurs at line 2, the catch block at line 4 will be executed. This catch block will print "1 " and then the finally block at line 10 will be executed. The finally block will print "3". Therefore, the result will be "1 3".

Submit
56. Java keywords are written in lowercase as well as uppercase

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.

Submit
57. What is an instanceof

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.

Submit
58. Given the below code. What is the result?    class Test    {        public static void main(String args[]) {                 String str = "null";                 if (str == null) {                         System.out.print("1");                 } else if (str.length() == 0) {                         System.out.print("2");                 } else {                         System.out.print("3");                 }         }   }

Explanation

The code initializes a string variable "str" with the value "null". The if statement checks if the string is null, which is true in this case. Therefore, the code inside the if block is executed, which prints "1". Since the condition in the else if statement is not satisfied, the code inside the else block is executed, which prints "3". Therefore, the final output is "3".

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

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.

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

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."

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

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.

Submit
62. The following statements make "length" be what number ?

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.

Submit
63. What will be the value of "num" after the following statements?

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.

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

Explanation

The code will not result in any errors because class B is a subclass of class A. Therefore, it is valid to create an instance of class B and assign it to a variable of type A.

Submit
65. Which is the valid declarations within an interface definition?

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.

Submit
66. 11.2 Q1: Intermixing program and error-handling logic:

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.

Submit
67. Given the code. What is the result? class Vehicle {     public void printSound() {         System.out.print("vehicle");     } }   class Car extends Vehicle {     public void printSound() {         System.out.print("car");     } }   class Bike extends Vehicle {     public void printSound() {         System.out.print("bike");     } }   public class Test {     public static void main(String[] args) {         Vehicle v = new Car();         Bike b = (Bike) v;                  v.printSound();         b.printSound();     }    }

Explanation

The code attempts to cast a Car object to a Bike object, which is not possible because Car is not a subclass of Bike. Therefore, a ClassCastException is thrown at runtime.

Submit
68. A class can be transient

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.

Submit
69. What is the output of below code snippet?  Map map=new HashMap();  String s1=new String("Key1");  String s2=new String("Key1");  map.put(s1,"Value1");  System.out.println(map.get(s2));

Explanation

The output of the code snippet will be "Value1". This is because even though s1 and s2 are different String objects, they have the same value ("Key1"). When s1 is used as the key to put "Value1" in the map, it is stored based on its value. When s2 is used as the key to retrieve a value from the map, it also has the same value as s1, so it successfully retrieves the corresponding value "Value1".

Submit
70. 11.1 Q1: Which of the following statements is false?

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.

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

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.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 22, 2023 +

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
Cancel
  • All
    All (71)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Java runs on _______.
 What is a loop ?
WHAT IS AN APPLET?
Java runs on _______.
What is Java (in regard to Computer Science) ?
 If you want your conditional to depend on two conditions BOTH...
What is a function in terms of Computer Science ?
If you want your conditional to depend on two conditions BOTH being...
 Booleans are _______.
What is an assignment statement ?
Which of the following means that in order for the conditional to...
What is the main function of any variable ?
Which of the following means that in order for the conditional to...
What is the proper way to declare a variable ?
Synchronized is a keyword to tell a Thread to grab an Object lock...
What's the difference between an Applet and an application ?
What is essential in making sure that your loop is not infinite ?
Which keyword is used to inherit class?
What is an Applet ?
What's the difference between an Applet and an application ?
Following code will result in: int a = 3.5;
Synchronized is a keyword to tell a Thread to grab an Object lock...
The methods wait(), notify() and notifyAll() in Object need to be...
Methods that are marked protected can be called in any subclass of...
The following prototype shows that a Cylinder subclass is derived from...
The methods wait(), notify() and notifyAll() in Object need to be...
Primitive datatypes are allocated on a stack
What does AWT stands for ?
Which is right way to creating an array of integer in java?
 Following code will result in: int a = 9/0;
An abstract class can have non-abstract methods
Can you compare a boolean to an integer?
Which of the java classes that cannot be subclassed?
With inheritance, a derived subclass object can directly access any
You can construct a new Color by providing 3 integers that represent...
How can you prevent a member variable from becoming serialized?
In a 'for' loop, what section of the loop is not included in the...
An abstract class should have methods all declared abstract?
Following code will result in: class A { int b = 1; public static void...
In which memory area of JVM objects will be created?
Inner classes can be defined within methods
Inner classes can be defined within methods.
How can you prevent a member variable from becoming serialized?
Following code will result in: int a1 = 5; double a2 = (float)a1;
The applet can  received the parameter values using the method...
Following code will result in: class A { public static void...
The default statement of a switch is always executed
Following code will result in: class A { public static void...
Following code will result in: float a = 9/0
Why can't the whole program just consist of the one line that does...
Given the code. What is the result after the class TryMe execution? ...
Which is NOT a section of all types of loops ?
11.3 Q2: Which of the following is not included in an exception’s...
Following code will result in: class A { public static void...
Given the code. What is the result if NullPointerException occurs at...
Java keywords are written in lowercase as well as uppercase
What is an instanceof
Given the below code. What is the result? ...
Integer a = new Integer(2); Integer b = new Integer(2); What happens...
 The finalize() method present in Object class is called just...
If class A implements an interface does it need to implement all...
The following statements make "length" be what number ?
What will be the value of "num" after the following statements?
Following code will result in: class A { public static void...
Which is the valid declarations within an interface definition?
11.2 Q1: Intermixing program and error-handling logic:
Given the code. What is the result? ...
A class can be transient
What is the output of below code snippet? ...
11.1 Q1: Which of the following statements is false?
11.3 Q3: Which of the following statements regarding the throw point...
Alert!

Advertisement