Java Review - Arrays, Methods, Classes And Inheritance

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 MrsQ
M
MrsQ
Community Contributor
Quizzes Created: 5 | Total Attempts: 3,269
| Attempts: 188 | Questions: 46
Please wait...
Question 1 / 46
0 %
0/100
Score 0/100
1. If a methods will not return a value you use this Java keyword as the return type.

Explanation

In Java, when a method does not return a value, the return type used is "void". This keyword is used to indicate that the method does not have a return value and simply performs a certain action or task. It is commonly used for methods that perform operations or modify data without needing to return any specific value.

Submit
Please wait...
About This Quiz
Java Quizzes & Trivia

This Java Review quiz focuses on arrays, methods, classes, and inheritance. It tests understanding of method access modifiers, method overloading, and the use of keywords like 'return' and... see more'void'. Ideal for learners looking to reinforce Java OOP concepts. see less

2. This Java keyword modifier makes members and variables of a class accessible outside of that class to everyone.

Explanation

The "public" keyword in Java is a modifier that allows members and variables of a class to be accessed by any other class or object. It provides the highest level of accessibility, allowing unrestricted access to the public members from anywhere in the code. This means that any class or object can access and modify the public members of a class without any restrictions or limitations.

Submit
3. This Java keyword allows you to inherit from another object/class.

Explanation

The Java keyword "extends" is used to inherit from another object/class. Inheritance allows a class to inherit the properties and methods of another class, known as the superclass or parent class. By using "extends", a subclass can inherit all the fields and methods of the superclass, and it can also add its own additional fields and methods. This keyword is essential in achieving code reusability and creating a hierarchical relationship between classes.

Submit
4. This Java keyword modifier makes members and variables of a class inaccessible outside of that class.

Explanation

The keyword "private" in Java is used as a modifier to restrict the access of members and variables of a class. When a member or variable is declared as private, it cannot be accessed or modified from outside the class. It ensures encapsulation and data hiding, allowing only the class itself to have direct access to its private members. This provides better control over the accessibility and visibility of class components, ensuring proper data protection and preventing unwanted modifications or access from other classes.

Submit
5. The private members of a class are not directly accessible outside of the class.

Explanation

Private members of a class are only accessible within the class itself and cannot be accessed outside of it. This is because private members have restricted visibility and are intended to be used only by the class itself, not by any external entities. This encapsulation feature helps to ensure data integrity and security by preventing direct access to sensitive information from outside the class. Therefore, the given answer, "True," correctly states that private members of a class are not directly accessible outside of the class.

Submit
6. This Java keyword modifier makes members and variables of a class accessible to other classes within a package.

Explanation

The "protected" keyword in Java is a modifier that allows members and variables of a class to be accessible to other classes within the same package. This means that any class within the package can access and use these protected members and variables. However, classes outside the package cannot access them unless they inherit from the protected member or variable. This keyword provides a level of encapsulation and control over the accessibility of class members and variables within a package.

Submit
7. In Java Arrays are objects.

Explanation

In Java, arrays are objects because they are created using the "new" keyword, they can be assigned to variables, and they have methods and properties like other objects. Arrays in Java are used to store multiple values of the same type in a single variable, and they can be dynamically resized. Therefore, the statement "In Java, arrays are objects" is true.

Submit
8. A constructor automatically execute when a class object is instantiated.

Explanation

A constructor is a special method that is automatically executed when an object of a class is created. It is used to initialize the object's state or perform any necessary setup tasks. Therefore, when a class object is instantiated, the constructor is automatically executed. This ensures that the object is properly initialized before it can be used.

Submit
9. A reference variable of a class can refer to either an object of its own class or an object of its subclass.

Explanation

A reference variable of a class can refer to either an object of its own class or an object of its subclass because a subclass inherits all the properties and behaviors of its superclass. This means that an object of the subclass can be treated as an object of the superclass, allowing the reference variable of the superclass to refer to it. This is known as polymorphism, where a single variable can refer to different types of objects.

Submit
10. This Java keyword exits the method and allows for a variable to be passed out of the method.

Explanation

The Java keyword "return" is used to exit a method and also allows for a variable to be passed out of the method. When the return statement is executed, it immediately ends the execution of the method and returns control back to the calling method. It can also return a value or an object that can be used by the calling method.

Submit
11. Constructors permit the data members to be initialized when an object is instantiated.

Explanation

Constructors are special member functions in a class that are used to initialize the data members of an object when it is created. They are called automatically when an object is instantiated. By using constructors, we can ensure that the data members have initial values as desired. Therefore, the statement "Constructors permit the data members to be initialized when an object is instantiated" is true.

Submit
12. This Java keyword calls the constructor in the parent class.

Explanation

The keyword "super" in Java is used to call the constructor of the parent class. It is often used when creating a subclass to initialize the inherited members from the parent class. By using "super", the subclass can access the parent class constructor and pass the necessary arguments to it. This allows the subclass to inherit and utilize the functionality of the parent class.

Submit
13. When you have a method in the child class with the same name as the parent class, this is called:

Explanation

When a child class has a method with the same name as a method in its parent class, it is called overriding. This means that the child class is providing its own implementation of the method, which will be used instead of the implementation in the parent class when the method is called on an object of the child class. This allows the child class to modify or extend the behavior of the parent class's method.

Submit
14. Int iArrNumbers[][] = new int[4][5] Examine the Java code above: How many columns are in the array?

Explanation

The given Java code creates a two-dimensional array named iArrNumbers with 4 rows and 5 columns. Therefore, the correct answer is 5.

Submit
15. If you don't call the parental constructor Java will automatically call the parent's default constructor.

Explanation

In Java, if a child class does not explicitly call the constructor of its parent class, Java will automatically call the parent class's default constructor. This means that if the child class does not have a constructor that calls the parent's constructor, the parent's default constructor will be invoked by default. Therefore, the statement "If you don't call the parental constructor Java will automatically call the parent's default constructor" is true.

Submit
16. What method do you use to determine the number of elements in an array?

Explanation

The length method is used to determine the number of elements in an array. It returns the size or length of the array, which represents the total number of elements stored in it. By using the length method, you can easily retrieve the count of elements in an array without having to manually iterate through each element.

Submit
17. This Java keyword refers to methods or variables within the current class.

Explanation

The keyword "this" in Java refers to methods or variables within the current class. It is used to differentiate between instance variables and parameters or local variables with the same name. It allows us to access the current object's instance variables and methods.

Submit
18. When this Java keyword is added to class declaration or to a method declaration, the class cannot be extended and the method cannot be overwritten.

Explanation

The keyword "final" in Java is used to indicate that a class cannot be extended or a method cannot be overwritten. When added to a class declaration, it prevents any other class from inheriting from it. When added to a method declaration, it ensures that the method cannot be overridden by any subclass. This keyword is often used when you want to prevent further modification or extension of a class or method, ensuring that they remain unchanged and maintain their functionality.

Submit
19. Non-static methods of a class are called instance methods.

Explanation

Non-static methods in a class are known as instance methods because they are associated with instances or objects of that class. These methods can access and modify the instance variables and are called using an object of the class. In contrast, static methods are associated with the class itself and can be called without creating an instance of the class. Therefore, the statement that non-static methods of a class are called instance methods is correct.

Submit
20. This Java keyword causes a class to be instantiated and the constructor called.

Explanation

The Java keyword "new" is used to create an instance of a class and invoke its constructor. It is followed by the name of the class and parentheses, which may contain arguments for the constructor if necessary. By using "new", an object of the specified class is created and memory is allocated for it. The constructor of the class is then called, initializing the object.

Submit
21. When you have a methods with the same name but they take in different parameters, it is called:

Explanation

When you have methods with the same name but they take in different parameters, it is called overloading. Overloading allows us to have multiple methods with the same name but different parameter lists, so that we can perform similar operations on different types of data. This helps in making the code more modular and flexible, as we can reuse the same method name for different variations of the method.

Submit
22. Java's static keyword when used in the method declaration allows that method to be invoked by just using the name of the class.

Explanation

The static keyword in Java, when used in the method declaration, allows that method to be invoked by just using the name of the class. This means that the method can be called without creating an instance of the class. Static methods are associated with the class itself rather than with any specific instance of the class. Therefore, they can be accessed directly using the class name followed by the method name. This is a key feature of the static keyword in Java.

Submit
23. Members of a class are accessed by name usually with a . preceding the name.

Explanation

In object-oriented programming, class members are typically accessed by name with a dot preceding the name. This is because the dot operator is used to access the properties and methods of an object. By using the dot operator, we can specify the object instance followed by the member name to access and manipulate its values or behaviors. Therefore, the statement "Members of a class are accessed by name usually with a . preceding the name" is true.

Submit
24. Examine the code below and indicate how many array elements are in the array? int iNumbers [];

Explanation

The code declares an array called "iNumbers" but does not specify the size or initialize any elements. Therefore, the number of array elements in the array is not defined.

Submit
25. Int iArrNumbers[][] = new int[4][5] Examine the Java code above: How many array elements are there?

Explanation

The Java code creates a 2-dimensional array called iArrNumbers with 4 rows and 5 columns. The total number of elements in the array can be calculated by multiplying the number of rows (4) by the number of columns (5), which equals 20. Therefore, there are 20 array elements in total.

Submit
26. A class can't have more than one constructor.

Explanation

A class can have more than one constructor. This allows for different ways of initializing objects of that class, depending on the parameters passed to the constructor. Having multiple constructors can provide flexibility and convenience when creating objects, as different constructors can handle different scenarios or variations in object initialization.

Submit
27. The three Java method method access modifiers are:

Explanation

The three Java method access modifiers are private, public, and protected. These modifiers determine the accessibility of a method within a class or outside of it. The private modifier restricts the access to only within the class itself. The public modifier allows the method to be accessed from anywhere. The protected modifier allows access within the class, its subclasses, and other classes in the same package. These access modifiers provide control over the visibility and accessibility of methods in Java.

Submit
28. Examine the following code and does it accomplish the same thing? int score[]; int [] score;

Explanation

The given code is declaring an integer array named "score" in two different ways. Both declarations are valid and accomplish the same thing, which is creating an integer array named "score". Therefore, the code does accomplish the same thing in both cases.

Submit
29. Int iArrNumbers[][] = new int[4][5] Examine the Java code above: How many rows are in the array?

Explanation

The Java code declares a 2-dimensional array called iArrNumbers with 4 rows and 5 columns. The statement "new int[4][5]" creates an array with 4 rows, so the answer is 4.

Submit
30. Which of the following statements would you use to call a private method named InitializeVariables that accepts no parameters and doesn't return a value?

Explanation

The correct statement to call a private method named InitializeVariables that accepts no parameters and doesn't return a value is InitializeVariables();. This statement directly calls the method by using its name followed by parentheses, indicating that no arguments are passed to the method.

Submit
31. A class is a collection of a specific number of components.

Explanation

A class is a fundamental concept in object-oriented programming. It is a blueprint or template for creating objects that share similar properties and behaviors. A class can contain a specific number of components, such as attributes (data) and methods (functions). These components define the characteristics and actions of the objects created from the class. Therefore, the statement "A class is a collection of a specific number of components" is true.

Submit
32. Int iArrNumbers[][] = new int[4][5] Examine the Java code above: Write the Java statement to access the element in the second row and third column in the iArrNumbers array:

Explanation

The Java statement "iArrNumbers[1][2]" is used to access the element in the second row and third column of the iArrNumbers array. In Java, arrays are zero-indexed, so the first index "1" refers to the second row, and the second index "2" refers to the third column. Therefore, "iArrNumbers[1][2]" will access the element at the position (1, 2) in the array.

Submit
33. Methods can return more than one primitive data type or object.

Explanation

Methods in most programming languages can only return a single value, either a primitive data type or an object. It is not possible for a method to return multiple values directly. However, there are workarounds to achieve a similar effect, such as returning an object that encapsulates multiple values or using output parameters. In general, though, a method can only have a single return type. Therefore, the given statement is false.

Submit
34. The class you inherit to in OOPS terms is referred to by either of these two names:

Explanation

In object-oriented programming, when you create a new class that derives from an existing class, it is called inheritance. The class that is being derived from is commonly referred to as the superclass or parent class. The new class that inherits from the superclass is known as the subclass or child class. Therefore, both "subclass" and "child class" are correct terms to refer to the class you inherit in OOPS.

Submit
35. When Arrays are passed a parameter to a method they are passed as:

Explanation

When arrays are passed as a parameter to a method, they are passed by reference. This means that any changes made to the contents of the array within the method will be reflected back in the original array in the called area of the code. In other words, the method can modify the array directly and the changes will persist outside of the method.

Submit
36. The three characteristics of OOP we have learned about are (make sure list them in the order we learned them):

Explanation

The three characteristics of OOP that we have learned about are encapsulation, inheritance, and polymorphism. Encapsulation refers to the bundling of data and methods within a class, allowing for data hiding and abstraction. Inheritance allows for the creation of new classes based on existing classes, enabling code reuse and the formation of hierarchical relationships. Polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling flexibility and extensibility in code design.

Submit
37. This Java keyword can be used when dealing with Polymorphism to determine what type an Object is. It can be used with a if statement because it equates to either true or false.

Explanation

The keyword "instanceof" in Java is used to determine the type of an object when dealing with polymorphism. It is commonly used in conjunction with an "if" statement to check if an object is an instance of a particular class or interface. The "instanceof" operator returns either true or false, indicating whether the object is of the specified type or not.

Submit
38. When you call a method with a parameter list, the arguments in the argument list:

Explanation

When you call a method with a parameter list, the arguments in the argument list must be coded in the same sequence and have the same data types as the parameters. This means that the order in which the arguments are passed must match the order of the parameters in the method declaration, and the data types of the arguments must match the data types of the corresponding parameters. This ensures that the method is called correctly and that the values passed as arguments can be properly assigned to the parameters within the method.

Submit
39. A method must take incoming parameters.

Explanation

This statement is false because a method does not necessarily have to take incoming parameters. Methods can be defined with or without parameters depending on the requirements of the program. Some methods may not require any input from the user or other parts of the program, and therefore can be defined without any parameters.

Submit
40. What object does every class ultimately inherit from in Java?

Explanation

In Java, every class ultimately inherits from the Object class. The Object class is the root class of all classes in Java and provides basic functionalities that are common to all objects, such as the toString() and equals() methods. By inheriting from the Object class, all other classes in Java inherit these basic functionalities and can be treated as objects.

Submit
41. For each parameter in the parameter list for a method, you must code:

Explanation

The correct answer is "the data type of the parameter followed by the name of the parameter". When coding the parameters for a method, it is necessary to specify the data type of each parameter followed by its corresponding name. This allows the compiler to understand the type of data that is expected to be passed into the method when it is called. By following this convention, it ensures that the correct data is being used and prevents any potential errors or misunderstandings.

Submit
42. The class you inherit from in OOPS terms is referred to by either of these two names:

Explanation

In object-oriented programming, when you inherit from a class, the class you inherit from is commonly referred to as either the superclass or the parent class. These terms are used interchangeably to describe the class that is being extended or inherited from. The superclass or parent class provides the base functionality and attributes that can be inherited by the subclass or child class.

Submit
43. If you pass a primitive data type variable such as int iCount to a method called doubleIt. The method doubleIt can change its value and have it reflected back in the code that it was called from.

Explanation

When a primitive data type variable is passed to a method, its value is passed by value, meaning that a copy of the variable's value is made and passed to the method. Therefore, any changes made to the variable within the method will not be reflected back in the code that called the method. In other words, the original variable will remain unchanged.

Submit
44. Overloading a method is when the Java class has multiple methods with the same name but the return types are different.

Explanation

Overloading a method is when the Java class has multiple methods with the same name but different parameters. The return types of the methods can be the same or different. This allows for flexibility and convenience when calling methods with different input parameters but the same functionality.

Submit
45. Classes that are defined within another class are called what in Java?

Explanation

In Java, classes that are defined within another class are called inner classes. Inner classes have access to the variables and methods of the outer class and can be used to encapsulate related functionality within a single class. Inner classes can be further classified as static inner classes, which do not have access to the instance variables of the outer class, and non-static inner classes, which can access both static and non-static members of the outer class.

Submit
46. Write the method declaration for a method that is called getValues that only the class it is defined in can access and it returns a String array. Note: Leave only one space between when supplying a value.

Explanation

The method declaration is specifying a private access modifier, which means that only the class in which it is defined can access the method. The method is named "getValues" and it returns a String array.

Submit
View My Results

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

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

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 05, 2012
    Quiz Created by
    MrsQ
Cancel
  • All
    All (46)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
If a methods will not return a value you use this Java keyword as the...
This Java keyword modifier makes members and variables of a class...
This Java keyword allows you to inherit from another object/class.
This Java keyword modifier makes members and variables of a class...
The private members of a class are not directly accessible outside of...
This Java keyword modifier makes members and variables of a class...
In Java Arrays are objects.
A constructor automatically execute when a class object is...
A reference variable of a class can refer to either an object of its...
This Java keyword exits the method and allows for a variable to be...
Constructors permit the data members to be initialized when an object...
This Java keyword calls the constructor in the parent class.
When you have a method in the child class with the same name as the...
Int iArrNumbers[][] = new int[4][5]...
If you don't call the parental constructor Java will automatically...
What method do you use to determine the number of elements in an...
This Java keyword refers to methods or variables within the current...
When this Java keyword is added to class declaration or to a method...
Non-static methods of a class are called instance methods.
This Java keyword causes a class to be instantiated and the...
When you have a methods with the same name but they take in different...
Java's static keyword when used in the method declaration allows...
Members of a class are accessed by name usually with a . preceding the...
Examine the code below and indicate how many array elements are in the...
Int iArrNumbers[][] = new int[4][5]...
A class can't have more than one constructor.
The three Java method method access modifiers are:
Examine the following code and does it accomplish the same thing?...
Int iArrNumbers[][] = new int[4][5]...
Which of the following statements would you use to call a private...
A class is a collection of a specific number of components.
Int iArrNumbers[][] = new int[4][5]...
Methods can return more than one primitive data type or object.
The class you inherit to in OOPS terms is referred to by either of...
When Arrays are passed a parameter to a method they are passed as:
The three characteristics of OOP we have learned about are (make sure...
This Java keyword can be used when dealing with Polymorphism to...
When you call a method with a parameter list, the arguments in the...
A method must take incoming parameters.
What object does every class ultimately inherit from in Java?
For each parameter in the parameter list for a method, you must code:
The class you inherit from in OOPS terms is referred to by either of...
If you pass a primitive data type variable such as int iCount to a...
Overloading a method is when the Java class has multiple methods with...
Classes that are defined within another class are called what in Java?
Write the method declaration for a method that is called getValues...
Alert!

Advertisement