Java Objective Test

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 Aniketve
A
Aniketve
Community Contributor
Quizzes Created: 2 | Total Attempts: 825
| Attempts: 550 | Questions: 93
Please wait...
Question 1 / 93
0 %
0/100
Score 0/100
1. What is the difference between private and public functions ?

Explanation

Public functions can be accessed and used by anyone, regardless of where they are called from. On the other hand, private functions can only be accessed and used by other code within the same class. This means that private functions are not accessible outside of the class they are defined in, providing encapsulation and data hiding.

Submit
Please wait...
About This Quiz
Java Objective Test - Quiz

The 'Java Objective Test' assesses understanding of Java and Object-Oriented Programming concepts. It covers class-object relationships, access modifiers, inheritance, and class members, focusing on key skills for Java... see moredevelopers. see less

2. 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 elements such as icons, buttons, and menus. This interface provides a visual representation of the system's functions and enables users to easily navigate and interact with the system without needing to use complex commands or programming languages.

Submit
3. Java runs on _______.

Explanation

Java is a platform-independent programming language, which means it can run on multiple operating systems. It is designed to be compatible with various platforms, including Windows, Unix/Linux, and Mac. This allows Java programs to be executed on any of these operating systems without requiring any modifications. Therefore, the correct answer is "All of the Above."

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. In object-oriented programming, a class serves as a blueprint or template for creating objects. It defines the properties and behaviors that objects of that class will have. The data elements in a class are the variables or attributes that store information, while the function elements are the methods or functions that define the behavior of the objects.

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. A class is a blueprint or template that defines the properties and behaviors of an object. When we create an object, we are creating a specific instance of that class, with its own unique set of values for the properties defined in the class. Therefore, an object can be seen as a concrete representation of a class, with its own state and behavior.

Submit
6. 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 values {1,2,3,4,5}. The index of an array starts from 0, so ar[3] refers to the fourth element in the array, which is 4.

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

Explanation

The value 5.5 is a decimal number with a fractional part, so it cannot be represented by an integer data type. The appropriate data type to store this value would be a double, which is a data type used to represent floating-point numbers with decimal places.

Submit
8. What is a loop ?

Explanation

A loop is a segment of code that is designed to be executed a specified number of times. It allows for the repetition of a certain block of code until a specific condition is met. This is achieved by using loop control statements such as "for" or "while" loops. By using loops, developers can avoid writing repetitive code and make their programs more efficient and concise.

Submit
9. 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 makes sense because the class Person is the superclass and the classes Student, Staff, and Faculty are subclasses. Therefore, it is valid to create an array of type Person[] and assign objects of any of the subclasses to it.

Submit
10. 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
11. 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 in the given declaration, the array "ar" is initialized with values {1,2,3,4,5}. In an array, the index starts from 0, so ar[4] refers to the fifth element of the array, which is 5.

Submit
12. 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 expression "System.out.print("The number is : " + nums[0]);" will display the first element in the array (i.e., the number 8). This is because "nums[0]" accesses the element at index 0 in the array "nums", which is the first element. The expression concatenates the string "The number is : " with the value of "nums[0]" and prints it to the console.

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

Explanation

The range of indices for an array always starts at 0. In most programming languages, arrays are zero-based, meaning that the first element of the array is accessed using the index 0. This convention is widely followed in order to maintain consistency and simplicity in array operations. Therefore, when working with arrays, it is important to remember that the index of the first element is always 0.

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

Explanation

The correct answer is boolean because the value "true" represents a boolean data type, which can only have two possible values: true or false.

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

Explanation

The value "1" is a whole number and does not have any decimal places, so it can be represented using the integer data type. Integers are used to store whole numbers without any fractional part.

Submit
16. 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 the server. Applets were commonly used in the early days of the internet to provide interactive content, such as games or animations, on web pages. However, with the rise of more powerful web technologies like JavaScript and HTML5, the usage of applets has significantly declined.

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

Explanation

example: kindOfBird = "Parrot"

Submit
18. 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 in Java. These methods allow threads to wait for a certain condition to be met and notify other threads when that condition is fulfilled. However, these methods can only be called from synchronized pieces of code. This is because synchronized blocks or methods ensure that only one thread can access the shared resource at a time, preventing concurrent modification and ensuring thread safety. Therefore, to use wait(), notify(), and notifyAll(), it is necessary to synchronize the code block or method in which these methods are called.

Submit
19. 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. This is 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 value of "num" is then reassigned to 9, overriding the previous value. Therefore, the final value of "num" is 9.

Submit
20. 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 AND operator in many programming languages, including C++, Java, and JavaScript. It returns true if both conditions are true, and false otherwise.

Submit
21. 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, it grabs the lock on the object associated with that block, allowing only itself to execute the code within the block. Other threads attempting to access the same block will have to wait until the lock is released. Therefore, the statement that "synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution" is true.

Submit
22. Which one needs a web page to run

Explanation

A Java Applet needs a web page to run because it is a small application that is designed to be embedded within a web page. It is executed within a web browser's Java Virtual Machine (JVM) and can interact with the web page's HTML content. Unlike a Java Application or Stand-Alone Application, which can be run independently on a computer, a Java Applet requires the infrastructure provided by a web page to be displayed and executed.

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

Explanation

The last value in an array called ar can be found at index ar.length - 1 because the index of an array starts from 0. So, if the length of the array is n, the last element will be at index n - 1.

Submit
24. 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
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 and parentheses, which can be used to pass arguments to the class constructor if needed. The "new" keyword dynamically allocates memory for the object and returns a reference to it, allowing the object to be accessed and manipulated in the program.

Submit
26. Primitive datatypes are allocated on a stack.

Explanation

Primitive datatypes are allocated on a stack because they are small and simple types that do not require complex memory management. The stack is a region of memory that is used for local variables and function calls, and it is efficient for allocating and deallocating memory quickly. When a primitive datatype is declared, it is allocated on the stack, and when it goes out of scope or is no longer needed, the memory is automatically freed. Therefore, the statement "Primitive datatypes are allocated on a stack" is true.

Submit
27. 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 statement means that the conditional will be true if either x is less than 3 or y is greater than or equal to 4. The double pipe symbol "||" represents the logical OR operator, which means that either condition can be true for the overall condition to be true. The "=" symbol represents greater than or equal to. Therefore, this statement accurately represents the condition described in the question.

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

Explanation

The correct answer is "class Cylinder extends Circle" because it indicates that the class "Cylinder" is a subclass that 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 unique properties and methods.

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

Explanation

The appropriate data type for the value "A" would be char. Char data type is used to store a single character in Java. In this case, "A" is a single character and can be stored as a char data type.

Submit
30. 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 a program. They allow us to assign values to a specific memory location and retrieve those values later on. By using variables, we can store and access data efficiently, making it easier to perform calculations and manipulate information within a program.

Submit
31. 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 likely representing a whole number quantity of eggs. The double data type is used for decimal numbers, char is used for single characters, and boolean is used for true/false values.

Submit
32. 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 subclasses have the ability to call and use these protected methods. The protected access modifier allows for more flexibility and access within the inheritance hierarchy, ensuring that subclasses have the necessary access to these methods for proper functionality. Therefore, the statement is true.

Submit
33. 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 syntax for creating a new JButton object is to use the "new" keyword followed by the class name, and then provide the desired caption in double quotes.

Submit
34. 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 and manipulate data by giving a variable a specific value. In this case, assigning a value to a variable is the correct answer as it accurately describes the purpose and function of an assignment statement.

Submit
35. 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. Therefore, the correct answer is that a derived subclass object can directly access public superclass members and protected subclass members if it's in the same package.

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

Explanation

Class names and Strings always need a capital letter because it is a common convention in programming languages to use capital letters to distinguish between different types of identifiers. Class names are typically written in CamelCase, where each word starts with a capital letter, while Strings are enclosed in quotation marks and can contain any combination of letters, numbers, and symbols. Using capital letters helps to improve code readability and maintain consistency in the naming conventions.

Submit
37. 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. They are typically written in Java and are designed to be embedded into web pages. On the other hand, applications are standalone programs that are installed and run directly on a computer or device. They are not limited to running within a web browser. Therefore, the correct answer is that applets are run over the web, distinguishing them from applications.

Submit
38. 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 provide a default implementation that can be inherited by the subclasses, while abstract methods are meant to be implemented by the subclasses. Therefore, it is possible for an abstract class to have non-abstract methods.

Submit
39. What does AWT stands for ?

Explanation

AWT stands for Abstract Window Toolkit. AWT is a set of classes and tools in Java that provide the foundation for creating graphical user interfaces (GUIs) for Java applications. It includes components such as buttons, menus, and text fields, as well as layout managers for arranging these components on a window. AWT is platform-independent and provides a way to create GUIs that can run on different operating systems. Therefore, the correct answer is Abstract Window Toolkit.

Submit
40. 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
41. Can you compare a boolean to an integer?

Explanation

A boolean is a data type that can only have two possible values: true or false. An integer, on the other hand, is a numeric data type that represents whole numbers. These two data types are not directly comparable because they are of different types and have different representations. Therefore, it is not possible to directly compare a boolean to an integer.

Submit
42. What is a member of a class

Explanation

A member of a class refers to any attribute or method that is associated with that class. It can be either an attribute, which represents the data or state of the class, or a method, which represents the behavior or actions that the class can perform. Therefore, a member of a class can be either an attribute or a method, making the answer "attribute or method" correct.

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

Explanation

The value "volatile" is a sequence of characters, which makes it suitable to be stored as a String data type.

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

Explanation

The correct answer is "perform the same operation on all elements in array". Arrays are commonly used to store a collection of similar data types. By using loops or other methods, we can easily apply the same operation to each element in the array, such as performing calculations, updating values, or displaying information. This allows for efficient and organized processing of data in a uniform manner.

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

Explanation

When a class A is declared as abstract, it means that it cannot be instantiated. Abstract classes can have abstract methods, which are methods without a body. These abstract methods must be implemented by any concrete subclass of A, but not necessarily by the abstract class itself. Therefore, when class A is abstract, it does not need to implement all the methods of the interface it implements.

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

Explanation

Since Class B inherits from Class A, it can access the protected and public 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 derived class. Therefore, it cannot be said that B has access to private members of A.

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

Explanation

In a 'for' loop, the loop body is not included in the parentheses after 'for'. The loop body is the section of the loop that contains the code to be executed repeatedly. The parentheses after 'for' typically include the initialization, test statement, and update sections of the loop. The loop body is enclosed within curly braces {} and is executed repeatedly until the test statement evaluates to false.

Submit
48. 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". It then enters a for loop that starts with the index 0 and increments by 2 in each iteration until the condition i
In the first iteration, it prints the character at index 0, which is "a".
In the second iteration, it prints the character at index 2, which is "c".

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

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

Explanation

Java keywords are written in lowercase only. In Java, keywords are predefined reserved words that have specific meanings and cannot be used as identifiers (such as variable names or method names). These keywords are case-sensitive, meaning that they must be written in lowercase letters exactly as they are defined in the Java language specification. Writing Java keywords in uppercase would result in a compilation error. Therefore, the given statement is false.

Submit
50. Inner classes can be defined within methods.

Explanation

Inner classes can be defined within methods. This statement is true. In Java, it is possible to define a class inside another class, and this inner class can also be defined within a method. Inner classes have access to the variables and methods of the outer class, and they can be useful for encapsulation and organization of code. However, it's important to note that inner classes defined within methods are not commonly used and are considered less common than inner classes defined within the scope of a class.

Submit
51. 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
52. 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 measured using decimal numbers, and the double data type can store decimal values with a higher precision compared to float. Using char would not be appropriate as it can only store a single character. String would not be suitable as it is used to store textual data rather than numerical values. Boolean would not be appropriate either as it is used to represent true or false values.

Submit
53. 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 matching case is found, that specific case statement is executed, and the default statement is skipped. Therefore, it is incorrect to say that the default statement is always executed.

Submit
54. 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 array is initialized with 6 elements: 1, 2, 3, 4, 5, and 6. Therefore, the size of the array is equal to the number of elements it contains, which is 6.

Submit
55. An object could be ...

Explanation

The given answer "anything" is correct because the question states that an object could be anything. This means that it can be any physical or abstract entity, such as an algorithm, a data container, or a program. The word "anything" encompasses all possibilities and allows for a broad interpretation of what an object can be.

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

Explanation

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

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

Explanation

The word "while" is not a section of all types of loops. The word "while" is specifically used in the syntax of the while loop, but it is not present in other types of loops such as the for loop or the do-while loop. The initialization, loop body, and test statement are common sections found in all types of loops.

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

Explanation

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

Submit
59. Which one is not correct?

Explanation

The given answer is correct because it states that class and object are just different names for the same thing. However, this statement is not true. In object-oriented programming, a class is a blueprint or template for creating objects, while an object is an instance of a class. A class defines the properties and behaviors that an object of that class will have, but the class itself and the object are not the same thing.

Submit
60. A class is...

Explanation

A class is an abstract definition of an object because it serves as a blueprint or template for creating objects of that class. It defines the properties and behaviors that the objects of that class will have. The class itself is not an object, but rather a conceptual representation of the object. Objects are instances of a class, created based on the class definition, and they possess the characteristics and behaviors specified by the class.

Submit
61. 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 the specific layout manager they want to use for organizing the widgets on the panel. The layout manager determines the positioning and sizing of the widgets, providing a consistent and organized appearance to the user interface. By calling setLayout, the programmer can customize the layout to suit their needs and achieve the desired arrangement of widgets on the panel.

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

Explanation

male / female = boolean (only two possible answers)

Submit
63. A class cannot be declared:

Explanation

A class cannot be declared as private because a private access modifier restricts the visibility of a class to only within its own class. This means that the class cannot be accessed or inherited by any other class in the program. Private access is typically used for variables and methods within a class to ensure encapsulation and data hiding, but it cannot be applied to the class itself.

Submit
64. 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 is a decimal number (6.7). In Java, you cannot assign a decimal value to an integer variable without explicitly converting it. Therefore, the code will fail to compile.

Submit
65. 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. Static variables and methods belong to the class itself, not to any specific instance of the class. Therefore, they can be accessed using the class name followed by the dot operator, without needing an instance of the class. However, a null reference does not refer to any instance of the class, so it cannot be used to access static members.

Submit
66. 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 in mathematics, and it will throw a runtime exception in most programming languages.

Submit
67. 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 in other packages.

Submit
68. 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 conversion from an integer to a double. The integer value 5 is explicitly casted to a float before being assigned to the double variable a2. This is allowed in Java and will not cause any compilation or runtime errors.

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 given code will result in a compile error because it is trying to create an instance of class A using the constructor of class B. However, class B is a subclass of class A, so it cannot be used to create an instance of class A. This violates the principle of inheritance and results in a compile error.

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

Explanation

The keyword "integer" is not a valid Java keyword. In Java, the correct keyword for representing integer values is "int". The other options listed are all valid Java keywords. "main" is used as the entry point for a Java program, "try" is used for exception handling, and "String" is used to represent a sequence of characters.

Submit
71. 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 correct answer is "The relationship from ATM to ATM Display". In the given scenario, the ATM class has a relationship with the ATM Display class, which is represented as an association in UML. This association indicates that the ATM class interacts with the ATM Display class by calling its methods or accessing its attributes.

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

Explanation

String's always have " " around them!

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

Explanation

A JFrame can be used as the main container in a Java application because it is a top-level container that provides a window for the application. It allows the application to have a title bar, minimize and maximize buttons, and other features typically associated with a window. JApplet is used for creating applets, JPanel is used for organizing and grouping components, and JButton is a specific type of component used for creating buttons. Therefore, JFrame is the most suitable choice for the main container in a Java application.

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

Explanation

The size of a Char in Java is 16 bits. In Java, the Char data type represents a single character and is stored using Unicode encoding, which uses 16 bits to represent each character. This allows Java to support a wide range of characters from different languages and ensures compatibility across different platforms and systems.

Submit
75. 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 a set of components and classes for creating graphical user interfaces (GUIs) in Java. It includes classes for creating and managing windows, buttons, panels, and other GUI elements. The java.awt package also provides GUI components, but javax.swing is generally preferred for its enhanced features and better performance. The javax.gui and java.swing options are incorrect as they do not exist in Java's standard library.

Submit
76. What is an instanceof?

Explanation

The correct answer is "An operator and keyword." The instanceof operator in Java is used to check whether an object is an instance of a specific class, a subclass, or a class that implements a particular interface. It returns true if the object is an instance of the specified class or interface, and false otherwise. As such, instanceof is both an operator and a keyword in Java.

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

Explanation

The description is not a part of defining an object. When defining an object, we need to specify its name, methods, and associations with other objects. The description, although it may provide additional information about the object, is not essential for its definition.

Submit
78. 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 that the Boolean statement, which acts as the condition for the loop, will eventually be false. This means that the loop will only continue running until the Boolean statement evaluates to false, at which point the loop will terminate.

Submit
79. 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, ensuring that it is displayed at the desired size. By calling this method, the programmer can dynamically adjust the size of the frame during runtime, providing flexibility and customization options.

Submit
80. 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 allowed in mathematics, and it will throw a runtime exception called "ArithmeticException: divide by zero".

Submit
81. 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 assign an instance of class B to a variable of type A. The code will run without any issues and the output will be "No errors".

Submit
82. 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. These properties allow the developer to specify the width and height of the applet in pixels. This ensures that the applet is displayed in the desired size when it is embedded within a web page. The other options mentioned, such as using the method setSize() or the width and height attributes of the class JApplet, are not correct in this context.

Submit
83. 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 allows for efficient access and manipulation of the elements within the array. By storing similar values of the same data type, we can easily perform operations on the elements using array indexing and looping constructs.

Submit
84. A UML association is ...

Explanation

A UML association represents a relationship between two or more classes. In Java, this association is typically implemented as a Java attribute member, which means that a class will have a variable that represents the association with another class. This allows objects of one class to have a reference to objects of another class, enabling them to interact and collaborate. By implementing the association as a Java attribute member, the relationship between the classes can be easily established and accessed.

Submit
85. Native methods can be 'abstract'

Explanation

Native methods cannot be 'abstract' because native methods are implemented in a different programming language, typically C or C++, and are used to access functionality that is not available in Java. Abstract methods, on the other hand, are methods that are declared but do not have an implementation. Therefore, it is not possible for a native method to be abstract.

Submit
86. 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 adds the widget mainPanel to the frame using the "add" method of the frame itself.

Submit
87. A class can be transient

Explanation

A class cannot be transient. The transient keyword is used in Java to indicate that a variable should not be serialized when the class is being converted to a byte stream. It is not applicable to classes themselves. Therefore, the statement that a class can be transient is false.

Submit
88. 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 the same (both 2), they are two separate objects created using the "new" keyword. Therefore, the "==" operator returns false because a and b do not refer to the same memory location.

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. 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) without creating an instance of the class.

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

Explanation

A UML association from class A to class B means that class A has an attribute of type B. This means that instances of class A can have a reference to instances of class B as one of their attributes. It does not imply inheritance, that class B is defined within class A, or that class B has an attribute of type A.

Submit
92. Object-Oriented Programming means ...  

Explanation

Object-Oriented Programming means designing the application based on the objects discovered when analyzing the problem. This approach focuses on breaking down the problem into smaller, manageable objects and then designing the program around these objects. It also involves writing an algorithm before writing the program and having a test plan to ensure the program functions correctly. Writing a program composed of Java classes is a specific implementation of Object-Oriented Programming, but it does not encompass the entire concept.

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

Explanation

The method getContentPane() returns the content pane of the applet, and the add() method is used to add the widget mainPanel to the content pane. Therefore, getContentPane().add(mainPanel) adds the widget mainPanel to an applet in the init method of the applet.

Submit
View My Results

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

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

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

Advertisement