The Ultimate Java Test For Beginners

Reviewed by Godwin Iheuwa
Godwin Iheuwa, MS (Computer Science) |
Database Administrator
Review Board Member
Godwin Iheuwa, a Database Administrator at MTN Nigeria, holds an MS in Computer Science, specializing in Agile Methodologies and Database Administration from the University of Bedfordshire and a Bachelor's in Computer Science from the University of Port Harcourt. His proficiency in SQL Server Integration Services (SSIS) and SQL Server Management Studio contributes to his expertise in database management.
, MS (Computer Science)
By Xooxa
X
Xooxa
Community Contributor
Quizzes Created: 1 | Total Attempts: 32,755
| Attempts: 32,755 | Questions: 93
Please wait...
Question 1 / 93
0 %
0/100
Score 0/100
1. 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. Therefore, the correct answer is "All of the Above" as Java can run on all these operating systems.

Submit
Please wait...
About This Quiz
The Ultimate Java Test For Beginners - Quiz

This is the ultimate Java test for all those Java developer-wannabes who have just began practicing the programming language. It consists of over 93 questions of basically Core... see moreJava. So, if you are one of them and want to have a solid practice session to strengthen your hold on the concepts and methods, take it right now.
see less

2. 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. This encapsulation allows for better control and organization of code, as private functions are not accessible or usable by code outside of the class.

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

Explanation

The correct answer is boolean. The value "true" is a boolean value, which represents a logical true or false. It is used to store and manipulate boolean data in programming. The int data type is used for storing whole numbers, double is used for storing floating-point numbers, and String is used for storing textual data. However, in this case, the value "true" is specifically a boolean value.

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

Explanation

The value 5.5 is a decimal number, so the appropriate data type to represent it is double.

Submit
5. 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 for creating objects, defining their properties (data) and behaviors (functions). It encapsulates the attributes and methods that an object will possess, allowing multiple objects to be created from the same class with their own unique data values.

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

Explanation

The value "1" is a whole number and does not contain any decimal places. Therefore, the appropriate data type for this value would be "int" which stands for integer. Integers are used to represent whole numbers in programming languages.

Submit
7. 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 contains the elements {1,2,3,4,5}. The index 3 refers to the fourth element in the array, which is 4.

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

Explanation

The given declaration initializes an integer array "ar" with the 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. Therefore, the value of ar[4] is 5.

Submit
9. 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 nums[0] accesses the first element in the array nums, which is 8.

Submit
10. 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, including popular ones like C, C++, Java, and Python, arrays are zero-indexed. This means that the first element of an array is accessed using the index 0. Therefore, the correct answer is 0.

Submit
11. 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 or template for creating objects. Objects have properties (attributes) and behaviors (methods) defined by the class, and they can interact with other objects. This definition accurately captures the concept of an object in the context of programming and distinguishes it from the other options provided.

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

Explanation

The appropriate data type for the value "A" is char. The value "A" represents a single character and can be stored in a char variable.

Submit
13. 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 is the standard syntax used in most programming languages. By declaring the variable type first, the compiler or interpreter knows how much memory to allocate for the variable and what operations can be performed on it. The variable name is then used to refer to the value stored in the memory location allocated for the variable.

Submit
14. 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 "&&".

Submit
15. What does GUI stand for?

Explanation

The correct answer is "Graphical User Interface". GUI stands for Graphical User Interface, which refers to the visual elements (such as icons, buttons, and windows) that allow users to interact with a computer system. It provides a user-friendly way to navigate and operate software applications, making it easier for users to perform tasks and access information.

Submit
16. 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 set of instructions until a specific condition is met. By using loops, programmers can avoid writing the same code multiple times, making their programs more efficient and concise.

Submit
17. 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 both Staff and Faculty are subclasses of Person. Therefore, an array of type Person can hold objects of type Faculty, Staff, and Student, as they all inherit from Person.

Submit
18. What is an Applet?

Explanation

An applet is a Java program that is designed to be run through a web browser. Unlike standalone Java programs, applets are embedded within webpages and are executed on the client side. They are typically used to add interactive features to websites, such as animations, games, or multimedia content. Applets are written in the Java programming language and are executed within a Java Virtual Machine (JVM) that is embedded in the web browser. This allows the applet to be platform-independent and run on any device with a compatible web browser and JVM.

Submit
19. 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 allow us to save values that can be accessed and modified later in the program. By assigning values to variables, we can store and retrieve data, perform calculations, and make decisions based on the stored values. Variables play a crucial role in programming as they enable the storage and manipulation of data, making programs more dynamic and flexible.

Submit
20. What is an assignment statement?

Explanation

An assignment statement is used to assign a value to a variable. It is a fundamental concept in programming where a variable is given a specific value. This allows the variable to store and manipulate data throughout the program. In this context, the correct answer is "Assigning a value to a variable" because it accurately describes the purpose and functionality of an assignment statement.

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

Explanation

example: kindOfBird = "Parrot"

Submit
22. 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. The first statement assigns the value of 9 to "num" by evaluating the expression (5+4). The second statement divides the value of "num" (which is currently 9) by 9, resulting in 1. However, this value is not stored in "num" as the third statement assigns the value of 9 to "num" again, overriding the previous value. Therefore, the final value of "num" is 9.

Submit
23. 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 using a Java Virtual Machine (JVM) plugin. The web page provides the necessary environment and resources for the applet to run, such as HTML, CSS, and JavaScript. Applets are commonly used for interactive web content, such as games or multimedia applications.

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

Explanation

The appropriate data type for the field "numberOfEggs" would be int. This is because the field is representing a count or quantity of eggs, which is typically a whole number and does not require decimal places. The int data type is used to store integer values, making it suitable for this scenario.

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

Explanation

The explanation for the given answer is that the "synchronized" keyword in Java is used to ensure that only one thread can access a block of code or a method at a time. When a thread encounters a synchronized block, it grabs the object lock associated with that block before executing the code inside. This ensures that other threads cannot access the same block of code until the lock is released by the current thread. Therefore, the statement that synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution is true.

Submit
26. 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 the conditional will be true if either x is less than 3 or y is greater than or equal to 4. The "||" operator represents the logical OR, which means that if either condition is true, the entire expression will be true.

Submit
27. Primitive datatypes are allocated on a stack.

Explanation

Primitive datatypes are allocated on a stack because they are small and fixed in size. The stack is a region of memory that is used for local variables and function calls. When a primitive datatype is declared, it is allocated on the stack and its value is stored directly in that memory location. This allows for efficient memory management and quick access to the value. Additionally, since the stack is organized as a last-in-first-out data structure, allocating and deallocating memory for primitive datatypes is very simple and fast.

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

Explanation

A boolean is a data type that can only have two values: true or false. An integer, on the other hand, is a data type that represents whole numbers. Since a boolean and an integer are different data types, they cannot be directly compared. In most programming languages, attempting to compare a boolean to an integer would result in a type mismatch error.

Submit
29. 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 it holds and waits until another thread notifies it. Similarly, the notify() and notifyAll() methods are used to wake up waiting threads. Since these methods manipulate the internal state of the object, they should only be called from synchronized code to ensure thread safety and avoid potential race conditions.

Submit
30. 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 array indices start at 0. So, if the length of the array is n, the indices will range from 0 to n-1. Therefore, the last value will be at the index ar.length - 1.

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

Explanation

The value "volatile" is a sequence of characters, which makes it a textual data. Therefore, the appropriate data type to represent this value would be a String.

Submit
32. 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
33. Choose the appropriate data type for this field: weightInKilos    

Explanation

The field "weightInKilos" suggests that it is meant to store a numerical value representing weight. The data type "double" is appropriate for this field because it allows for decimal values, which are commonly used to represent weight. The data types "char" and "boolean" are not suitable for storing numerical values, and the data type "String" is not ideal for numerical calculations or comparisons.

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

Explanation

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

Submit
35. 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 parent class, it can be called and used in any child class that inherits from the parent class. The protected access modifier allows for a level of encapsulation, where certain methods or variables are accessible only within the class and its subclasses. Therefore, the statement "Methods that are marked protected can be called in any subclass of that class" is true.

Submit
36. 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 the first option: for (int i =0; i

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 syntax follows the format of creating a new JButton object and assigning it to the variable "aButton", while passing the string "test" as the caption parameter in double quotes.

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

Explanation

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

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

Explanation

An abstract class is a class that cannot be instantiated and is meant to be inherited by other classes. It can have both abstract and non-abstract methods. Abstract methods are declared without any implementation and must be overridden by the subclass, while non-abstract methods have a complete implementation and can be used as-is by the subclass. Therefore, it is true that an abstract class can have non-abstract methods.

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

Explanation

In Java, the keyword "new" is used to create an object. 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. By using the "new" keyword, we can instantiate an object of a class and access its properties and methods.

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

Explanation

Applets are a type of software program that can be run within a web browser. They are typically used to enhance the functionality of a website by providing interactive features. On the other hand, applications are standalone software programs that are installed on a computer and can be run independently of a web browser. Therefore, the main 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.

Submit
42. 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 to indicate that the class Cylinder is derived from the superclass Circle. In object-oriented programming, inheritance allows a subclass to inherit the properties and methods of its superclass, and by extending Circle, the Cylinder subclass can access and use the attributes and behaviors defined in the Circle class.

Submit
43. 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
44. 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. When an inner class is defined within a method, it is called a local inner class. Local inner classes have access to the variables and methods of the enclosing method, which can be useful in certain situations. However, it is important to note that local inner classes can only be accessed within the method in which they are defined.

Submit
45. 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. This is because the array has 6 elements inside the curly braces {1, 2, 3, 4, 5, 6}. Each element takes up one slot in the array, so the size of the array is equal to the number of elements it contains, which in this case is 6.

Submit
46. 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 (variable names, method names, etc.). These keywords are case-sensitive, meaning that using uppercase letters in keywords will result in a compilation error. Therefore, the statement that Java keywords can be written in both lowercase and uppercase is false.

Submit
47. 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 for efficient storage and retrieval of multiple values of the same data type. By applying a single operation to each element in the array, tasks such as calculations, transformations, or comparisons can be easily performed on a large set of data. This allows for concise and efficient coding, as the same code can be applied to each element in the array without the need for repetitive code or manual iteration.

Submit
48. An object could be ...

Explanation

The given correct answer for this question is "anything". This is because the question states that an object could be anything, including an algorithm, a data container, or a program. The term "anything" encompasses all possibilities and allows for flexibility in the definition of an object.

Submit
49. A class is...

Explanation

A class is an abstract definition of an object because it represents the blueprint or template for creating objects of that class. It defines the properties (attributes) and behaviors (methods) that the objects of that class will have. The class itself is not an object, but rather a description or definition of what an object of that class should be like. Objects are instances of classes, created based on the class definition, and they have their own unique state and behavior.

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

Explanation

The value "female" is text-based, making String the most appropriate data type. If only storing a single character, such as 'F' or 'M', then Char would be a valid option. Boolean is incorrect because it represents only true or false, not multiple categories. Int and Double are numerical types and do not apply to gender data. When designing databases or applications, using String ensures flexibility, especially if other gender options are included. Many modern systems also allow custom gender identities, making String the best choice.

Submit
51. 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 of the switch expression. If there is a case that matches the switch expression, the corresponding case statement will be executed and the default statement will be skipped. Therefore, the correct answer is False.

Submit
52. What is a member of a class

Explanation

A member of a class refers to any attribute or method that belongs to that class. It can be either an attribute, which represents the data associated with the class, or a method, which represents the behavior or actions that the class can perform. In object-oriented programming, classes are used to define objects, and attributes and methods are the building blocks that make up these objects. Therefore, a member of a class can be either an attribute or a method, or it can be both.

Submit
53. 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 and can only serve as a base class for other classes. In this case, if class A implements an interface, it does not need to implement all the methods of that interface. The responsibility of implementing the interface methods is passed on to the concrete subclasses that extend class A. Therefore, the correct answer is "No, not when A is abstract."

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

Explanation

The word "while" is not a section of all types of loops. The options provided are common sections found in loops, such as initialization, loop body, and test statement. However, the word "while" is a keyword used to define a specific type of loop in some programming languages, like the while loop. Therefore, it is not a section that is present in all types of loops.

Submit
55. 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 same class and cannot be accessed by its subclasses. Therefore, the statement "B has access to private members of A" cannot be said.

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

Explanation

The code will result in a compilation error because it is trying to assign a floating-point value (6.7) to an integer variable (num). In Java, an integer variable can only store whole numbers, not decimal values. To fix this error, either the variable type should be changed to a floating-point type (e.g., double) or the value should be rounded or truncated to an integer.

Submit
57. 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. It is enclosed within curly braces {} and is executed for each iteration of the loop. The initialization, test statement, and update sections are all included within the parentheses after 'for'.

Submit
58. What does AWT stand 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 collection of classes and methods that allow developers to create and manage windows, buttons, menus, and other GUI components. It is the foundation of Java's GUI programming and is used to build desktop applications in Java.

Submit
59. 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 from 0 and increments by 2 until it reaches 4. Inside the loop, it prints the character at the index "i" of the string "word".

In the first iteration of the loop, when "i" is 0, it prints the character at index 0 which is 'a'. In the second iteration, when "i" is 2, it prints the character at index 2 which is 'c'. Since the loop condition is "
Therefore, the output of the code is "ac".

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

Explanation

In programming, class names and Strings (textual data) always require a capital letter at the beginning. This convention helps differentiate them from other elements in the code and follows standard coding practices for readability and consistency.

Submit
61. 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 attempting to do so in a program will throw a runtime exception called "ArithmeticException: DivideByZeroException".

Submit
62. 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 a valid mathematical operation and will throw a runtime exception called "ArithmeticException: divide by zero".

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

Explanation

In the context of Java programming, defining associations with other objects is not typically considered a direct part of defining a single object. While objects can have relationships with other objects, the act of defining a single object usually focuses on its attributes (description), methods, and name. Associating with other objects is more about the relationships between different objects in a broader system.

Submit
64. 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. It is a top-level container that provides a window for the application. It allows the addition of various components such as buttons, panels, and applets. It provides features like a title bar, minimize, maximize, and close buttons. The JFrame class also provides methods to handle events and perform actions. Therefore, it is commonly used as the main container for building graphical user interfaces in Java applications.

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 and not to any specific instance of the class. They can be accessed directly using the class name, without needing an instance of the class. Since a null reference does not refer to any instance of the class, it cannot be used to access static members.

Submit
66. Which of the following is not correct?

Explanation

The explanation for the given correct answer is that class and object are not the same thing. A class is a blueprint or template for creating objects, while an object is an instance of a class that exists in memory at runtime. They have different roles and functionalities in object-oriented programming.

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

Explanation

The given code will not result in any errors. It initializes an integer variable "a1" with the value 5, and then assigns this value to a double variable "a2" after casting it to a float. Since both int and float can be implicitly converted to double, there is no need for explicit type conversion in this case. Therefore, the code will compile and run without any errors.

Submit
68. 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

In the given scenario, the relationship from ATM to ATM Display will be shown as an association in UML. This means that the ATM class has a reference to the ATM Display class, indicating that it uses or interacts with the ATM Display class in some way. The association represents a dependency between the two classes, where the ATM class relies on the ATM Display class for its functionality.

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

Explanation

In Java, the size of a Char is 16 bits. This means that a Char variable can store any Unicode character as it has a larger range compared to other data types. Unicode characters are represented using UTF-16 encoding, which requires 16 bits to store each character. Therefore, the correct answer is 16 bits.

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

Explanation

In Java, Integer is a class, not a keyword. It’s part of the java.lang package and is used to wrap a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.

Submit
71. 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 will determine how the widgets are arranged on the panel. Different layout managers have different rules and algorithms for positioning and sizing the widgets, allowing for flexibility in the design of the user interface.

Submit
72. 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. However, class A is not a subclass of class B, so this assignment is not allowed.

Submit
73. 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 allows the loop to terminate and the program to continue executing the remaining code. By checking the Boolean statement at each iteration of the loop, the program can determine whether to continue or exit the loop based on the truth value of the statement. This prevents the loop from running indefinitely and causing the program to hang or crash.

Submit
74. 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 any class within the same package can access the member, but classes outside of the package cannot.

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

Explanation

The correct answer is the method setSize(). The size of a frame is set using the method setSize() in Java. This method allows you to specify the width and height of the frame, and it can be called at runtime to dynamically change the size of the frame.

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

Explanation

String's always have " " around them!

Submit
77. What is an instanceof?

Explanation

The correct answer is "An operator and keyword". The instanceof operator is used to check if 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. It is both an operator and a keyword because it is used in a similar way to other operators, but it also has a specific syntax and behavior defined by the language.

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

Explanation

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

Submit
79. Native methods can be 'abstract'

Explanation

Native methods cannot be 'abstract'. Abstract methods are methods that are declared in a class but do not have an implementation. Native methods, on the other hand, are methods that are implemented in a language other than Java, typically in a lower-level language like C or C++. Therefore, native methods must have an implementation and cannot be declared as abstract.

Submit
80. A class can be transient

Explanation

A class cannot be transient. The transient keyword in programming languages is used to indicate that a variable should not be serialized when an object is being converted into a stream of bytes. However, the transient keyword cannot be applied to classes themselves. It can only be used with variables. Therefore, the statement "A class can be transient" is incorrect.

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 the statement "A a = new B();" is valid. This is an example of polymorphism, where an object of a subclass can be assigned to a variable of its superclass. Therefore, the code will compile successfully without any errors.

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

Explanation

To use widgets such as JApplet, JFrame, JPanel, and JButton, you need to use the javax.swing package. This package provides classes and components for creating graphical user interfaces (GUIs) in Java. It includes a wide range of widgets and functionality for building interactive and visually appealing applications. The javax.gui, java.awt, and java.swing options are incorrect as they do not provide the necessary classes for creating these specific widgets.

Submit
83. 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 object of class A.

Submit
84. A UML association is ...

Explanation

A UML association is implemented as a Java attribute member because in UML, an association represents a relationship between two or more classes. In Java, this relationship is typically implemented by creating a member variable in one class that references an object of another class. This allows the two classes to interact and collaborate with each other. Therefore, implementing a UML association as a Java attribute member is the correct approach to represent the relationship between classes in the UML diagram.

Submit
85. A top-level class cannot be declared:

Explanation

A top-level class cannot be declared as private because the private access modifier restricts access to members within the same class only. It is used to hide the implementation details of a class and prevent other classes from accessing or inheriting it. However, a class can be declared as static or default (also known as package-private or no modifier), which allows access to other classes within the same package.

Submit
86. 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 they are referring to the same object in memory. In this case, although both a and b have the same value of 2, they are separate objects with different memory references. Therefore, the condition "a==b" will evaluate to False.

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

Explanation

The correct answer is "this.add(mainPanel)". This line of code adds the widget mainPanel to the frame using the "add" method. The "this" keyword refers to the current instance of the frame, and "mainPanel" is the widget that is being added.

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

Explanation

The correct answer is getContentPane().add(mainPanel) 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 ensures that the mainPanel is added to the applet correctly.

Submit
89. 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.

Submit
90. An array holds:

Explanation

An array is a data structure that stores a collection of elements of the same data type. These elements are stored in contiguous memory locations and can be accessed 1 using their index. Arrays are commonly used to store and manipulate collections of data, such as numbers, characters, or objects.  

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

Explanation



The correct answer is none of the above. The correct syntax for the Java main method is:

public static void main(String[] args)





This is the standard signature that the Java Virtual Machine (JVM) expects when executing a Java program. The main method must be public, static, and void, and it must accept a single parameter of type String array. The parameter name can be different from args, but it is the convention to use args.





The other options are incorrect for various reasons:





public void main(String[] args) is incorrect because the main method must be static, otherwise the JVM cannot invoke it without creating an object of the class.

public static void main(string[] args) is incorrect because the parameter type must be String, not string. Java is case-sensitive, and string is not a valid type in Java.





public static void main() is incorrect because the main method must accept a parameter of type String array, even if it is not used in the program. The parameter is used to pass command-line arguments to the program.

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

Explanation





 This means that instances of Class B are associated with instances of Class A in a way that Class B contains an attribute whose type is Class A. It doesn't necessarily mean every instance of B has an A, but there is a relationship between the two classes.

For example, if you have a UML diagram with classes `Car` and `Engine`, an association from `Car` to `Engine` would imply that a `Car` has an attribute, say `carEngine,` whose type is `Engine.`

This is different from option D, which would imply that every instance of `Car` has an attribute of type `Engine,` which may not be the case in a general association. Associations express relationships, not direct containment or inheritance.
Submit
93. Object-Oriented Programming means ...

Explanation

Object-Oriented Programming (OOP) is an approach to software development that focuses on designing and organizing a program or system around objects, which are instances of classes representing real-world entities or concepts. In OOP, you analyze the problem domain and model it using objects, encapsulation, inheritance, and polymorphism to create a more organized and modular software structure. So, OOP involves designing the application based on the objects discovered during the problem analysis phase.

Submit
View My Results
Godwin Iheuwa |MS (Computer Science) |
Database Administrator
Godwin Iheuwa, a Database Administrator at MTN Nigeria, holds an MS in Computer Science, specializing in Agile Methodologies and Database Administration from the University of Bedfordshire and a Bachelor's in Computer Science from the University of Port Harcourt. His proficiency in SQL Server Integration Services (SSIS) and SQL Server Management Studio contributes to his expertise in database management.

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

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

  • Current Version
  • Mar 21, 2025
    Quiz Edited by
    ProProfs Editorial Team

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

Advertisement