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: 816
| Attempts: 548
SettingsSettings
Please wait...
  • 1/93 Questions

    What is the difference between private and public functions ?

    • Public functions are free, you have to buy private ones
    • Public functions are the only ones you can download
    • Public functions can be used by anyone, private can only be used by other code in the class you are writing
    • Public functions can’t be used
Please wait...
About This 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 developers.

Java Objective Test - Quiz

Quiz Preview

  • 2. 

    What does GUI stand for?

    • Graphical User Interface

    • Gimme Ur Internet

    • Grand User Interface

    • Graphical Useful Interface

    Correct Answer
    A. Graphical User Interface
    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.

    Rate this question:

  • 3. 

    Java runs on _______.

    • Windows

    • Unix/Linux

    • Mac

    • All of the Above

    Correct Answer
    A. All of the Above
    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."

    Rate this question:

  • 4. 

    Choose the best definition for a Class.    

    • A group of students in a class

    • An object definition, containing the data and function elements necessary to create an object

    • An action for a program

    Correct Answer
    A. An object definition, containing the data and function elements necessary to create an object
    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.

    Rate this question:

  • 5. 

    Choose the best definition of an object

    • A thing

    • An instance of a class

    • Something you wear

    Correct Answer
    A. An instance of a class
    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.

    Rate this question:

  • 6. 

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

    • 2

    • 3

    • 4

    • 5

    Correct Answer
    A. 4
    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.

    Rate this question:

  • 7. 

    Choose the appropriate data type for this value: 5.5    

    • Int

    • Double

    • Boolean

    • String

    Correct Answer
    A. Double
    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.

    Rate this question:

  • 8. 

    What is a loop ?

    • A new type of Applet.

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

    • A segment of code to be run infinite times

    • A segment of code to be run once

    Correct Answer
    A. A segment of code to be run a specified amount of times
    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.

    Rate this question:

  • 9. 

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

    • Faculty[] faculties={new Person(), new Staff(), new Student()};

    • Staff[] staff={new Person(), new Faculty(), new Student()};

    • Person[] persons={new Faculty(), new Staff(), new Student()};

    Correct Answer
    A. Person[] persons={new Faculty(), new Staff(), new Student()};
    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.

    Rate this question:

  • 10. 

    Choose the appropriate data type for this value: 1

    • Int

    • Double

    • String

    • Boolean

    Correct Answer
    A. Int
    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.

    Rate this question:

  • 11. 

    What is the proper way to declare a variable ?

    • VariableName variableType;

    • VariableName;

    • VariableType;

    • VariableType variableName;

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

    Rate this question:

  • 12. 

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

    • 2

    • 3

    • 4

    • 5

    Correct Answer
    A. 5
    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.

    Rate this question:

  • 13. 

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

    • System.out.print("The number is : " + nums[0]);

    • System.out.print("The number is : " + nums[1]);

    • System.out.print("The number is : " + nums[8]);

    • System.out.print("The number is : " + nums);

    Correct Answer
    A. System.out.print("The number is : " + nums[0]);
    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.

    Rate this question:

  • 14. 

    Choose the appropriate data type for this value: true    

    • Int

    • Double

    • String

    • Boolean

    Correct Answer
    A. Boolean
    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.

    Rate this question:

  • 15. 

    What is an Applet ?

    • A Java program that does not run through a web browser

    • A Java program that is run through a web browser

    • An object-oriented programming language

    • An interactive website

    Correct Answer
    A. A Java program that is run through a web browser
    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.

    Rate this question:

  • 16. 

    The range of indices for an array always start at:

    • Whatever programmer specifies

    • 1

    • 0

    • Size of array

    Correct Answer
    A. 0
    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.

    Rate this question:

  • 17. 

    What will be the value of “num” after the following statements? int num; num = (5+4); num = num / 9; num = 9;

    • 9

    • 1

    • 0

    • Num

    Correct Answer
    A. 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.

    Rate this question:

  • 18. 

    Choose the appropriate data type for this field: kindOfBird    

    • String

    • Int

    • Char

    • Double

    Correct Answer
    A. String
    Explanation
    example: kindOfBird = "Parrot"

    Rate this question:

  • 19. 

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

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 20. 

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

    • True

    • False

    Correct Answer
    A. True
    Explanation
    The explanation for the given correct answer is that the "synchronized" keyword in Java is used to ensure that only one thread can access a block of code or an object at a time. When a thread encounters a synchronized block, 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.

    Rate this question:

  • 21. 

    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 ?

    • &

    • &&

    • |

    • ||

    Correct Answer
    A. &&
    Explanation
    The proper notation to put between two Boolean statements when you want your conditional to depend on both conditions being true is "&&". This is the logical AND operator in many programming languages, including C++, Java, and JavaScript. It returns true if both conditions are true, and false otherwise.

    Rate this question:

  • 22. 

    Which one needs a web page to run

    • A Java Application

    • A Java Stand-Alone Application

    • A Java Applet

    • A Java Class

    Correct Answer
    A. A Java Applet
    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.

    Rate this question:

  • 23. 

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

    • 0

    • 1

    • Ar.length

    • Ar.length - 1

    Correct Answer
    A. Ar.length - 1
    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.

    Rate this question:

  • 24. 

    What is the role of the constructor? 

    • Create an instance of a class (an object)

    • Create names for methods

    • To create some type of change in the state of an object

    Correct Answer
    A. Create an instance of a class (an object)
    Explanation
    Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object.

    Rate this question:

  • 25. 

    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 ?

    • If ((x < 3) && (y > 4))

    • If (x < 3 y >= 4)

    • If ((x < 3) || (y > = 4))

    • If ((x > 3) || (y < = 4))

    Correct Answer
    A. If ((x < 3) || (y > = 4))
    Explanation
    The correct answer is "if ((x < 3) || (y > = 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.

    Rate this question:

  • 26. 

    Choose the appropriate data type for this value: A    

    • Int

    • Double

    • Char

    • String

    Correct Answer
    A. Char
    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.

    Rate this question:

  • 27. 

    Primitive datatypes are allocated on a stack.

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 28. 

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

    • This

    • New

    • Sync

    • New()

    Correct Answer
    A. New
    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.

    Rate this question:

  • 29. 

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

    • Class Circle extends Cylinder

    • Class Cylinder derived Circle

    • Class Cylinder extends Circle

    • Class Circle derived Cylinder

    Correct Answer
    A. Class Cylinder extends 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.

    Rate this question:

  • 30. 

    How to define a JButton with the caption test?

    • JButton aButton('test');

    • JButton aButton=new JButton("test");

    • JButton aButton=new JButton('test');

    • JButton("test") aButton;

    Correct Answer
    A. JButton aButton=new JButton("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.

    Rate this question:

  • 31. 

    Choose the appropriate data type for this field: numberOfEggs    

    • Double

    • Char

    • Boolean

    • Int

    Correct Answer
    A. Int
    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.

    Rate this question:

  • 32. 

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

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 33. 

    What is the main function of any variable ?

    • To add numbers together

    • To keep track of data in the memory of the computer

    • To print words on the screen

    • To write Java codes

    Correct Answer
    A. To keep track of data in the memory of the computer
    Explanation
    The main function of any variable is to keep track of data in the memory of the computer. Variables are used to store and manipulate data in 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.

    Rate this question:

  • 34. 

    With inheritance, a derived subclass object can directly access any

    • Public or private superclass member

    • Private superclass member

    • Public superclass member (and protected subclass members if it's in the same package)

    • Protected, public or private superclass member

    Correct Answer
    A. Public superclass member (and protected subclass members if it's in the same package)
    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.

    Rate this question:

  • 35. 

    What is an assignment statement ?

    • Adding a number to an int

    • Assigning a multiplication

    • Assigning a name to a variable

    • Assigning a value to a variable

    Correct Answer
    A. Assigning a value to a variable
    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.

    Rate this question:

  • 36. 

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

    • None of the above.

    • Applets are run over the web.

    • Applets can paint words, applications cannot.

    • An application is only available on Windows

    Correct Answer
    A. Applets are run over the web.
    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.

    Rate this question:

  • 37. 

    Which of the following always need a Capital letter ?    

    • Class names and Strings

    • Objects and class names

    • Fields and Strings

    • Data types and fields

    Correct Answer
    A. Class names and Strings
    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.

    Rate this question:

  • 38. 

    An abstract class can have non-abstract methods.

    • True

    • False

    Correct Answer
    A. True
    Explanation
    An abstract class can have non-abstract methods because an abstract class is a class that cannot be instantiated and is meant to be extended by other classes. It can contain both abstract and non-abstract methods. Non-abstract methods 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.

    Rate this question:

  • 39. 

    What does AWT stands for ?

    • Advanced Window Toolkit

    • Abstract window Toolkit

    • Adjust Window Toolkit

    • None of the choices

    Correct Answer
    A. Abstract window Toolkit
    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.

    Rate this question:

  • 40. 

    Can you compare a boolean to an integer?

    • Yes

    • No

    Correct Answer
    A. No
    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.

    Rate this question:

  • 41. 

    What is a member of a class

    • An attribute

    • A method

    • Attribute or method

    • A sub-class

    Correct Answer
    A. Attribute or method
    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.

    Rate this question:

  • 42. 

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

    • 6

    • 2+4

    • 1+3

    • 4

    Correct Answer
    A. 6
    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.

    Rate this question:

  • 43. 

    Choose the appropriate data type for this value: "volatile"    

    • Int

    • String

    • Double

    • Boolean

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

    Rate this question:

  • 44. 

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

    • Yes, always.

    • No, not when A is abstract

    Correct Answer
    A. No, not when A is abstract
    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.

    Rate this question:

  • 45. 

    Class B inherits from Class A, what cannot be said:

    • B is a sub-class of A

    • A is a super-class of B

    • B has access to private members of A

    • B has access to protected members of A

    Correct Answer
    A. B has access to private members of A
    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.

    Rate this question:

  • 46. 

    The most common use of an array is to:

    • Perform for loop on array

    • Perform different operations on each element in array

    • Perform the same operation on all elements in array

    • Perform while loop on array

    Correct Answer
    A. Perform the same operation on all elements in array
    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.

    Rate this question:

  • 47. 

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

    • Initialization

    • Loop Body

    • Test statement

    • Update

    Correct Answer
    A. Loop Body
    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.

    Rate this question:

  • 48. 

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

    • Ab

    • Ac

    • Ace

    • Bd

    Correct Answer
    A. Ac
    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 < 4 is no longer true. In each iteration, it prints the character at the current index of "word".

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

    Rate this question:

  • 49. 

    Java keywords are written in lowercase as well as uppercase.

    • True

    • False

    Correct Answer
    A. False
    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.

    Rate this question:

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.