Java Quiz: Toughest Questions! Trivia MCQ

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 Kdjaafar
K
Kdjaafar
Community Contributor
Quizzes Created: 2 | Total Attempts: 1,619
| Attempts: 195 | Questions: 93
Please wait...
Question 1 / 93
0 %
0/100
Score 0/100
1. Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[4]?

Explanation

The value of ar[4] is 5 because arrays in most programming languages are zero-indexed, meaning that the first element is at index 0, the second element is at index 1, and so on. In this case, the fifth element of the array is at index 4, and it has a value of 5.

Submit
Please wait...
About This Quiz
Java Quiz: Toughest Questions! Trivia MCQ - Quiz

Challenge your Java knowledge with this trivia! Featuring tough questions on object-oriented programming, class accessibility, and object definitions, this quiz tests your understanding and skills in Java, enhancing... see moreyour programming acumen. see less

2. The range of indices for an array always start at:

Explanation

In programming, the range of indices for an array always starts at 0. This means that the first element in an array is accessed using the index 0, the second element with index 1, and so on. This convention is followed in many programming languages, including C, C++, Java, and Python. Starting the index at 0 allows for a more efficient and consistent way of referencing elements in an array.

Submit
3. 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 is because the keyword "extends" is used in Java to indicate that a class is derived from another class. In this case, the subclass "Cylinder" is derived from the superclass "Circle". This means that the "Cylinder" class inherits all the properties and methods of the "Circle" class, and can also have its own additional properties and methods.

Submit
4. Choose the best definition for a Class.    

Explanation

A class is an object definition that contains the data and function elements necessary to create an object. It serves as a blueprint or template for creating objects of that class. The class defines the properties and behaviors that the objects of that class will have.

Submit
5. Choose the best definition of an object

Explanation

The correct answer is "an instance of a class." In object-oriented programming, an object is an instance of a class, which is a blueprint for creating objects. Objects have properties (attributes) and behaviors (methods) defined by the class. This definition accurately describes the concept of an object in the context of programming.

Submit
6. Choose the appropriate data type for this value: true    

Explanation

The value "true" represents a boolean data type, which is used to store either true or false values. In this case, since the value is "true", the appropriate data type to store it would be boolean.

Submit
7. Choose the appropriate data type for this value: 5.5    

Explanation

The value 5.5 is a decimal number with a fractional component, which cannot be represented accurately using an integer data type. Therefore, the appropriate data type for this value is double, which is used to store floating-point numbers with a higher precision than float data type.

Submit
8. Choose the appropriate data type for this value: A    

Explanation

The appropriate data type for the value "A" is char because char is used to represent a single character in programming. In this case, "A" is a single character, so it can be stored as a char data type.

Submit
9. Java runs on _______.

Explanation

Java is a programming language that is designed to be platform-independent, meaning it can run on multiple operating systems. It is not limited to a specific operating system like Windows, Unix/Linux, or Mac. Therefore, the correct answer is "All of the Above" as Java can run on all of these operating systems.

Submit
10. What is a loop?

Explanation

A loop is a segment of code that is designed to be executed repeatedly for a specified number of times. It allows for the efficient repetition of a certain set of instructions, which can be useful in situations where the same task needs to be performed multiple times. By specifying the number of times the loop should run, the code within the loop can be executed repeatedly until the specified condition is met, providing a way to automate repetitive tasks and streamline programming processes.

Submit
11. Choose the appropriate data type for this field: numberOfEggs    

Explanation

The appropriate data type for the field "numberOfEggs" would be int because it is most commonly used to represent whole numbers without any decimal places. Since the number of eggs is typically a whole number, using int would be the most suitable choice.

Submit
12. If classes Student, Staff and Faculty extend class Person, which one makes sense:

Explanation

The correct answer is "Person[] persons={new Faculty(), new Staff(), new Student()};". This is because the class hierarchy suggests that Faculty, Staff, and Student are all types of Person. Therefore, an array of type Person can hold objects of any of these three classes. However, the other two options are not valid because they involve trying to assign objects of incompatible types to arrays.

Submit
13. Choose the appropriate data type for this value: 1

Explanation

The value 1 is a whole number and does not have any fractional or decimal part. Therefore, the appropriate data type for this value would be an integer (int). Integers are used to represent whole numbers in programming languages.

Submit
14. What is the role of the constructor? 

Explanation

Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object.

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 particular block of code or method at a time. When a thread encounters a synchronized block, it grabs the lock associated with the object and executes the code inside the block. This ensures that other threads have to wait until the lock is released before they can access the same code. 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 is an Applet?

Explanation

An applet is a Java program that is designed to be run through a web browser. It is embedded within an HTML page and is executed on the client-side. Applets are used to enhance the functionality of a web page by providing interactive features such as animations, games, and data visualization. They are typically smaller in size and have limited access to system resources compared to standalone Java applications.

Submit
17. The last value in an array called ar can be found at index:

Explanation

The last value in an array can be found at the index ar.length - 1 because arrays in most programming languages are zero-indexed, meaning the first element is at index 0. Therefore, the last element will be at the index equal to the length of the array minus one.

Submit
18. 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 provide default implementations that can be inherited by its subclasses. This allows the subclasses to use these methods without having to implement them again.

Submit
19. 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 correct notation to put between the 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, which returns true only if both conditions are true.

Submit
20. 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 inherits from that superclass. This allows for the subclass to have access to the protected method and utilize its functionality as needed. Therefore, the statement "Methods that are marked protected can be called in any subclass of that class" is true.

Submit
21. What is the difference between private and public functions?

Explanation

Public functions are accessible to anyone and can be used by any code, whether it is within the same class or outside of it. On the other hand, private functions can only be accessed and used by other code within the same class. They are not accessible or usable by any external code. This distinction allows for better encapsulation and control over the functionality of the class, as private functions can only be invoked and manipulated by the class itself.

Submit
22. Given the declaration int [ ] nums = {8, 12, 23, 4, 15}, what expression will display the first element in the array (ie the number 8)

Explanation

The correct answer is System.out.print("The number is : " + nums[0]); because the expression nums[0] accesses the first element in the array "nums" and concatenates it with the string "The number is : " to display the result.

Submit
23. What is the size of a Char in Java?

Explanation

In Java, the size of a Char is 16 bits. This means that it occupies 2 bytes of memory. The Char data type is used to represent a single character and can store Unicode characters as well. The 16-bit size allows for a wide range of characters to be represented, including those from different languages and special symbols.

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

Explanation

A boolean and an integer are two different data types and cannot be directly compared. They represent different types of values - a boolean represents a logical value of either true or false, while an integer represents a numerical value. Therefore, it is not possible to compare a boolean to an integer.

Submit
25. What is the keyword used in java to create an object?

Explanation

The keyword used in Java to create an object is "new". This keyword is followed by the name of the class that we want to create an object of, and it allocates memory for the object and returns a reference to it.

Submit
26. What is an assignment statement?

Explanation

An assignment statement is a statement in programming where a value is assigned to a variable. It is used to store a value in a variable so that it can be accessed and manipulated later in the program. In this case, assigning a value to a variable is the correct answer as it accurately describes the purpose of an assignment statement.

Submit
27. What will be the value of "num" after the following statements? int num; num = (5+4); num = num / 9; num = 9;

Explanation

The value of "num" will be 9 because the variable "num" is initially assigned the value of (5+4), which is 9. Then, the value of "num" is divided by 9, resulting in 1. However, the next statement assigns the value of 9 to "num", overwriting the previous value. Therefore, the final value of "num" is 9.

Submit
28. Which is not a part of defining an object?

Explanation

In object-oriented programming, defining an object involves specifying its methods, associations with other objects, and giving it a name. However, the description of an object is not a necessary part of its definition. While it can be helpful to provide a description for documentation or understanding purposes, it is not essential for defining the object itself.

Submit
29. If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:

Explanation

The size of the array "ar" is 6 because the given declaration "int [ ] ar = {1,2,3,4,5,6};" initializes an array with 6 elements. The numbers inside the curly braces represent the values of the elements in the array. Therefore, the size of the array is equal to the number of elements it contains, which in this case is 6.

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

Explanation

The proper way to declare a variable is by stating the variable type followed by the variable name. This ensures that the variable is properly defined and can be used in the program.

Submit
31. Choose the appropriate data type for this field: kindOfBird    

Explanation

example: kindOfBird = "Parrot"

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

Explanation

Inheritance allows a derived subclass object to directly access public superclass members. This means that the derived subclass object can use any public member of its superclass without any restrictions. 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 directly by the subclass object.

Submit
33. Primitive datatypes are allocated on a stack.

Explanation

Primitive data types in most programming languages are allocated on the stack. The stack is a region of memory that is used for local variables and function calls. When a primitive data type is declared, it is allocated on the stack and its value is stored directly in memory. This allows for fast and efficient access to the data. In contrast, objects and complex data types are typically allocated on the heap, which is a region of memory used for dynamic memory allocation.

Submit
34. 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 during the execution of a program. They provide a way to store values that can be accessed and modified throughout the program. By assigning values to variables, programmers can store and retrieve data as needed, making it easier to process and manipulate information in the computer's memory.

Submit
35. 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 answer correctly represents the condition that either x must be less than 3 or y must be greater than or equal to 4. The logical operator "||" represents the logical OR, which means that if either of the conditions is true, the entire condition will be true. Therefore, this answer accurately captures the requirement stated in the question.

Submit
36. What does GUI stand for?

Explanation

GUI stands for Graphical User Interface. It is a type of user interface that allows users to interact with electronic devices through graphical icons and visual indicators. This interface uses images, buttons, menus, and other graphical elements to enable users to perform tasks easily and intuitively. GUIs are widely used in software applications, operating systems, and websites to enhance user experience and make it more user-friendly.

Submit
37. How to define a JButton with the caption test?

Explanation

The correct answer is JButton aButton=new JButton("test"). This is the correct way to define a JButton with the caption "test". The JButton class provides a constructor that takes a String parameter, which represents the text that will be displayed on the button. By using the "new" keyword, we create a new instance of the JButton class and assign it to the variable "aButton". The String "test" is passed as an argument to the constructor, setting the caption of the button to "test".

Submit
38. What displays from the following statements? String word = "abcde"; for (int i = 0; i <4; i+=2) System.out.print(word[i]);

Explanation

The given code initializes a string variable "word" with the value "abcde". Then, it enters a for loop that starts with i=0 and increments i by 2 in each iteration until i
In the first iteration, i=0, so it prints the character at index 0 which is 'a'.
In the second iteration, i=2, so it prints the character at index 2 which is 'c'.

Thus, the output of the code is "ac".

Submit
39. Choose the appropriate data type for this field: weightInKilos    

Explanation

The appropriate data type for the field "weightInKilos" would be double. This is because weight is typically represented as a decimal number and the double data type can store decimal values with a higher precision compared to float. Using a double data type allows for more accurate and flexible calculations involving weight measurements.

Submit
40. Choose the appropriate data type for this field: isSwimmer    

Explanation

isSwimmer - yes or no (only two possible answers = boolean)

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

Explanation

The word "while" is not a section of all types of loops. It is specifically used in the syntax of the "while" loop, but not in other types of loops such as "for" or "do-while" loops. The "while" loop is a type of loop that continues to execute a block of code as long as a specified condition is true. Therefore, the word "while" is not a common section found in all types of loops.

Submit
42. A class is...

Explanation

A class is an abstract definition of an object because it defines the properties and behaviors that an object of that class should have. It serves as a blueprint or template for creating objects with similar characteristics. A class does not represent a specific object itself, but rather describes the common attributes and methods that objects of that class should possess.

Submit
43. What would display from the following statements? int [ ] nums = {1,2,3,4,5,6}; System.out.println((nums[1] + nums[3]));

Explanation

The given code initializes an array called "nums" with the values {1,2,3,4,5,6}. The statement "System.out.println((nums[1] + nums[3]));" prints the sum of the values at index 1 and index 3 of the array, which are 2 and 4 respectively. Therefore, the output will be 6.

Submit
44. Which one needs a web page to run?

Explanation

A Java Applet needs a web page to run because it is a small program that is designed to be embedded within a web page. It is executed within a web browser's Java Virtual Machine (JVM) and is typically used to add interactive features to a website. Unlike a Java Application or a Java Stand-Alone Application, which can be run independently on a computer, a Java Applet requires the infrastructure of a web page to be displayed and executed.

Submit
45. Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[3]?

Explanation

The value of ar[3] is 4 because in the given declaration, the array 'ar' is initialized with the values {1,2,3,4,5}. In an array, the index starts from 0, so ar[3] refers to the fourth element in the array, which is 4.

Submit
46. 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. These methods are used to implement the wait-notify mechanism, where a thread can wait for a certain condition to be satisfied and then notify other threads that the condition has been met. In order to avoid race conditions and ensure thread safety, these methods should be called within synchronized blocks or methods, which provide exclusive access to the shared resources.

Submit
47. 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 specific class or interface. It returns true if the object is an instance of the specified class or interface, and false otherwise. Therefore, it is both an operator and a keyword in Java.

Submit
48. Which of the following is not a Java keyword?

Explanation

The correct answer is "integer" because "integer" is not a Java keyword. Java keywords are reserved words that have a specific meaning and purpose in the Java programming language. Some examples of Java keywords include "main" and "try", which are used for defining the main method and handling exceptions, respectively. "String" is also a Java keyword, used for defining string variables and manipulating strings. However, "integer" is not a Java keyword and cannot be used as a keyword in Java programming.

Submit
49. What loop will display each of the numbers in this array on a separate line: float [ ] nums= {1.1f, 2.2f, 3.3f};

Explanation

The correct answer is "for (int i =0; i

Submit
50. Following code will result in: int num = 6.7;

Explanation

The code will result in a compilation error because the variable "num" is declared as an integer, but the value assigned to it (6.7) is a decimal or floating-point number. In Java, you cannot assign a floating-point value to an integer variable without explicit casting or converting the value to an integer.

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

Explanation

Java keywords are always written in lowercase. The Java language specification defines a set of reserved words that have predefined meanings and cannot be used as identifiers for variables, methods, or classes. These keywords are case-sensitive, meaning that they must be written in lowercase to be recognized by the Java compiler. Writing keywords in uppercase would result in a compilation error. Therefore, the statement that Java keywords are written in lowercase as well as uppercase is incorrect.

Submit
52. 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 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. Abstract classes are allowed to have abstract methods, which means they can leave the implementation of certain methods to their subclasses. Therefore, in this case, class A is exempted from implementing all the methods of the interface.

Submit
53. Which package do you need to use widgets such as JApplet, JFrame, JPanel and JButton?

Explanation

The correct answer is javax.swing. This package is needed to use widgets such as JApplet, JFrame, JPanel, and JButton. The javax.swing package provides classes and components for creating a graphical user interface (GUI) in Java. It includes various classes and methods that allow the creation and manipulation of GUI components, such as windows, buttons, panels, and applets.

Submit
54. If none of the private/protected/public is specified for a member, that member ...

Explanation

If none of the access modifiers (private/protected/public) is specified for a member, that member is only accessible by other classes of the same package. This means that the member can be accessed by any class within the same package, but not by classes outside of the package.

Submit
55. How is the layout of widgets on a panel specified?

Explanation

The layout of widgets on a panel is specified by calling the method setLayout. This method allows the programmer to choose a specific layout manager that determines how the widgets will be arranged on the panel. Different layout managers have different rules for positioning and resizing the widgets, allowing for flexibility in the design of the user interface. By calling setLayout, the programmer can customize the layout to meet the specific requirements of the application.

Submit
56. Following code will result in: int num = 8/0;

Explanation

The given code will result in a Runtime Exception. This is because dividing a number by zero is not a valid mathematical operation and it will throw an ArithmeticException at runtime.

Submit
57. An object could be ...

Explanation

The given correct answer, "anything," suggests that an object could refer to any entity or thing. It could be an algorithm, a data container, a program, or any other entity. This answer implies that the term "object" is not limited to a specific category or definition, but rather encompasses a broad range of possibilities.

Submit
58. Choose the appropriate data type for this value: "volatile"    

Explanation

The value "volatile" is a sequence of characters, which makes it suitable to be represented by the String data type. String data type is used to store text in programming languages.

Submit
59. Which of the following always need a Capital letter ?    

Explanation

Class names and Strings always need a capital letter because it is a standard convention in programming languages to use capital letters to differentiate between different types of identifiers. Class names represent the blueprint for creating objects, and by convention, they start with a capital letter to make them easily distinguishable from other identifiers. Similarly, Strings are a data type used to represent a sequence of characters, and by convention, they are also written with a capital letter to differentiate them from other variables or identifiers.

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

Explanation

In a 'for' loop, the section 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 no longer true. The initialization, test statement, and update sections are all included within the parentheses after 'for', while the loop body is enclosed within curly braces {}.

Submit
61. A class cannot be declared:

Explanation

A class cannot be declared as "Private" because the access modifier "Private" restricts the visibility of a class to only within the same class. It means that the class cannot be accessed or inherited by any other class outside of its own class. This would limit the usability and functionality of the class, as it would not be accessible to other parts of the program.

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

Explanation

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

Submit
63. Which one could be used as the main container in a Java application?

Explanation

JFrame can be used as the main container in a Java application because it provides a window for the application and acts as a top-level container. It allows other components to be added to it and provides various methods and functionalities to handle user interactions and display content. JApplet, JPanel, and JButton are not suitable as main containers as they have specific purposes within a Java application, such as creating applets, organizing components, and creating buttons, respectively.

Submit
64. Choose the appropriate data type for this value: female    

Explanation

male / female = boolean (only two possible answers)

Submit
65. Inner classes can be defined within methods.

Explanation

Inner classes can be defined within methods. This statement is true. In Java, inner classes are classes that are defined within another class. They can also be defined within methods, which makes them local to that method. This allows for more flexibility in organizing code and can be useful in certain situations where a class is only needed within a specific method.

Submit
66. What does AWT stands for?

Explanation

AWT stands for Abstract Window Toolkit. This is a set of application programming interfaces (APIs) provided by Java to develop graphical user interface (GUI) applications. AWT provides a collection of classes and methods that allow developers to create and manipulate windows, buttons, menus, and other GUI components. It is platform-independent and provides a way for Java programs to interact with the underlying operating system's windowing system. Therefore, the correct answer is Abstract Window Toolkit.

Submit
67. Which one is not correct?

Explanation

The given statement that "Class and object are just different names for the same thing" is not correct. In object-oriented programming, a class is a blueprint or template for creating objects. A class defines the properties and behaviors that an object of that class will have. On the other hand, an object is an instance of a class. It is created using the class blueprint and represents a specific entity with its own set of properties and behaviors. Therefore, a class and an object are not the same thing, but rather related concepts in object-oriented programming.

Submit
68. Which one adds the widget mainPanel to an applet in the init method of the applet?

Explanation

The correct answer is "getContentPane().add(mainPanel)". This is because the getContentPane() method returns the content pane of the applet, and the add() method is used to add the mainPanel widget to the content pane. This line of code adds the mainPanel widget to the applet's content pane in the init method.

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

Explanation

The 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, this assignment is not allowed and will cause a compile error.

Submit
70. What is a member of a class?

Explanation

A member of a class refers to either an attribute or a method. In object-oriented programming, a class is a blueprint for creating objects, and members are the variables (attributes) and functions (methods) associated with the class. These members define the characteristics and behaviors of the objects created from the class. Therefore, the correct answer is attribute or method, as both attributes and methods are considered members of a class.

Submit
71. The size of a frame is set using ...

Explanation

The size of a frame is set using the method setSize(). This method allows the programmer to specify the width and height of the frame in pixels. By calling this method, the programmer can dynamically adjust the size of the frame during runtime to meet their specific requirements.

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

Explanation

Applets are a type of software program that are designed to run within a web browser. They are typically written in Java and are used to add interactive features to web pages. On the other hand, an application is a standalone software program that is installed on a computer or mobile device and can be run independently of a web browser. Therefore, the correct answer that explains the difference between an Applet and an application is that Applets are run over the web.

Submit
73. 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 evaluated in the switch statement. If a case matches, the code block associated with that case is executed, and the default statement is skipped. Therefore, the correct answer is False.

Submit
74. The most common use of an array is to:

Explanation

The most common use of an array is to perform the same operation on all elements in the array. Arrays allow us to store multiple values of the same data type in a single variable. By using a loop or iteration, we can easily access each element in the array and apply the same operation to all of them. This is particularly useful when we want to perform a repetitive task or calculation on a set of data.

Submit
75. Class B inherits from Class A, what cannot be said:

Explanation

Since Class B inherits from Class A, it can access the protected members of Class A. However, it cannot access the private members of Class A. Private members are only accessible within the class they are defined in and cannot be accessed by any subclasses. Therefore, the statement "B has access to private members of A" cannot be said.

Submit
76. We have three classes: ATM, ATM Display and Account. The ATM has one ATM Display and works by calling methods on class Account. Which will be shown as an association in UML?

Explanation

The relationship from ATM to ATM Display will be shown as an association in UML. This means that the ATM class is associated with the ATM Display class, indicating that the ATM uses the methods and properties of the ATM Display class.

Submit
77. A null reference may be used to access a static variable or method.

Explanation

A null reference cannot be used to access a static variable or method because static members belong to the class itself and not to any specific instance of the class. Therefore, they can be accessed using the class name directly and do not require an instance of the class. A null reference represents the absence of an object, so it does not have access to any members, including static ones.

Submit
78. Native methods can be 'abstract'

Explanation

Native methods cannot be 'abstract' because native methods are implemented in a language other than Java, such as C or C++, and they are used to access platform-specific features or libraries. Abstract methods, on the other hand, are declared in an abstract class or interface and do not have an implementation. Therefore, it is not possible for a native method to be abstract.

Submit
79. Following code will result in: float num = 5/0;

Explanation

The given code will result in a Runtime Exception. This is because dividing a number by zero is not allowed and it will throw a runtime exception called "ArithmeticException: / by zero".

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

Explanation

The code will result in a compilation error because the variable "x" is an instance variable and cannot be accessed directly from a static method (main method). To fix this error, the variable "x" should either be declared as static or an instance of class A should be created to access the variable.

Submit
81. A UML association is ...

Explanation

In UML, an association represents a relationship between two or more classes. It is implemented as a Java attribute member, which means that it is represented as a variable or property within a class. This attribute member can hold a reference to an object of another class, establishing the association between them. By using this implementation, the classes can communicate and interact with each other through the association attribute, allowing them to access and manipulate the associated objects.

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

Explanation

The given code will not result in any errors because it involves a simple type casting operation. The variable "a1" is assigned the value 5, and then it is explicitly casted to a float type and assigned to the variable "a2" of double type. Since the casting is allowed between compatible numeric types, there will be no compilation or runtime errors.

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

Explanation

To ensure that a loop is not infinite, it is essential that the Boolean statement used as the condition for the loop will eventually become false. This is because a loop will continue executing as long as the Boolean statement is true. If the statement never becomes false, the loop will continue indefinitely, resulting in an infinite loop. Therefore, it is necessary to have a condition that can change to false at some point, allowing the loop to terminate and the program to progress.

Submit
84. Object-Oriented Programming means   

Explanation

Object-Oriented Programming (OOP) refers to a programming paradigm that focuses on designing software based on objects. It involves analyzing the problem, identifying relevant objects, and designing the application accordingly. While writing a program composed of Java classes is a characteristic of OOP, it is not the definition of OOP itself. Writing an algorithm before writing the program and having a test plan are important steps in the development process, but they are not exclusive to OOP.

Submit
85. A UML association from class A to class B means

Explanation

The correct answer is "Class A has an attribute of type B." This means that class A has a variable or attribute that is of type B, indicating a relationship between the two classes. This association does not imply inheritance, the class B being defined within class A, or class B having an attribute of type A.

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

Explanation

The given code will not result in any errors because class B extends class A, so it is valid to create an object of class B and assign it to a reference variable of class A. The code will compile successfully and run without any issues.

Submit
87. Choose the appropriate data type for this value: "1"    

Explanation

String's always have " " around them!

Submit
88. The size of an applet is set using ...

Explanation

The size of an applet is set using the HTML properties WIDTH and HEIGHT of the APPLET tag. This allows the developer to specify the desired width and height of the applet within the HTML code. The setSize() method is used to set the size of components within the applet, not the overall size of the applet itself. The width and height attributes of the class JApplet are not used to set the size of the applet.

Submit
89. What is the correct syntax for java main method?

Explanation

public static void main(String args[]) is the right format. String instead of string is the correct one.

Submit
90. 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, although the values of a and b are both 2, they are different objects with different memory locations. Therefore, the condition "a==b" evaluates to False.

Submit
91. Which one adds the widget mainPanel to a frame in the constructor of the frame?

Explanation

The correct answer is "this.add(mainPanel)" because it uses the "add" method to add the widget "mainPanel" to the frame.

Submit
92. An array holds:

Explanation

An array holds similar values of the same data type because it is a data structure that allows us to store multiple elements of the same type in a contiguous memory location. This means that all the elements in an array should have the same data type, such as integers, floats, characters, or strings. By storing similar values, we can easily access and manipulate the elements in the array using their indices.

Submit
93. A class can be transient

Explanation

A class cannot be transient. The transient keyword in programming languages like Java is used to indicate that a variable should not be serialized when an object is being converted to a byte stream. It does not apply to classes. Classes are not serialized, so the concept of making them transient does not exist. Therefore, the correct answer is False.

Submit
View My Results

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

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

  • Current Version
  • Mar 18, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 03, 2015
    Quiz Created by
    Kdjaafar
Cancel
  • All
    All (93)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of...
The range of indices for an array always start at:
The following prototype shows that a Cylinder subclass is derived from...
Choose the best definition for a Class.    
Choose the best definition of an object
Choose the appropriate data type for this value:...
Choose the appropriate data type for this value:...
Choose the appropriate data type for this value:...
Java runs on _______.
What is a loop?
Choose the appropriate data type for this field:...
If classes Student, Staff and Faculty extend class Person, which one...
Choose the appropriate data type for this value: 1
What is the role of the constructor? 
Synchronized is a keyword to tell a Thread to grab an Object lock...
What is an Applet?
The last value in an array called ar can be found at index:
An abstract class can have non-abstract methods.
If you want your conditional to depend on two conditions BOTH being...
Methods that are marked protected can be called in any subclass of...
What is the difference between private and public functions?
Given the declaration int [ ] nums = {8, 12, 23, 4, 15}, what...
What is the size of a Char in Java?
Can you compare a boolean to an integer?
What is the keyword used in java to create an object?
What is an assignment statement?
What will be the value of "num" after the following statements?...
Which is not a part of defining an object?
If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:
What is the proper way to declare a variable?
Choose the appropriate data type for this field:...
With inheritance, a derived subclass object can directly access any
Primitive datatypes are allocated on a stack.
What is the main function of any variable?
Which of the following means that in order for the conditional to...
What does GUI stand for?
How to define a JButton with the caption test?
What displays from the following statements? String word =...
Choose the appropriate data type for this field:...
Choose the appropriate data type for this field:...
Which is NOT a section of all types of loops?
A class is...
What would display from the following statements? int [ ] nums =...
Which one needs a web page to run?
Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of...
The methods wait(), notify() and notifyAll() in Object need to be...
What is an instanceof?
Which of the following is not a Java keyword?
What loop will display each of the numbers in this array on a separate...
Following code will result in: int num = 6.7;
Java keywords are written in lowercase as well as uppercase.
If class A implements an interface does it need to implement all...
Which package do you need to use widgets such as JApplet, JFrame,...
If none of the private/protected/public is specified for a member,...
How is the layout of widgets on a panel specified?
Following code will result in: int num = 8/0;
An object could be ...
Choose the appropriate data type for this value:...
Which of the following always need a Capital letter...
In a 'for' loop, what section of the loop is not included in the...
A class cannot be declared:
How can you prevent a member variable from becoming serialized?
Which one could be used as the main container in a Java application?
Choose the appropriate data type for this value:...
Inner classes can be defined within methods.
What does AWT stands for?
Which one is not correct?
Which one adds the widget mainPanel to an applet in the init method of...
Following code will result in: class A { public static void...
What is a member of a class?
The size of a frame is set using ...
What's the difference between an Applet and an application?
The default statement of a switch is always executed.
The most common use of an array is to:
Class B inherits from Class A, what cannot be said:
We have three classes: ATM, ATM Display and Account. The ATM has one...
A null reference may be used to access a static variable or method.
Native methods can be 'abstract'
Following code will result in: float num = 5/0;
Following code will result in: class A { int x = 1; public static...
A UML association is ...
Following code will result in: int a1 = 5; double a2 = (float)a1;
What is essential in making sure that your loop is not infinite?
Object-Oriented Programming means   
A UML association from class A to class B means
Following code will result in: class A { public static void...
Choose the appropriate data type for this value:...
The size of an applet is set using ...
What is the correct syntax for java main method?
Integer a = new Integer(2); Integer b = new Integer(2); What happens...
Which one adds the widget mainPanel to a frame in the constructor of...
An array holds:
A class can be transient
Alert!

Advertisement