Java Review - Arrays, Methods, Classes And Inheritance

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By MrsQ
M
MrsQ
Community Contributor
Quizzes Created: 5 | Total Attempts: 3,042
Questions: 46 | Attempts: 177

SettingsSettingsSettings
Java Quizzes & Trivia

Questions and Answers
  • 1. 

    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.

    Rate this question:

  • 2. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 3. 

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

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

    Rate this question:

  • 4. 

    A method must take incoming parameters.

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 5. 

    If a methods will not return a value you use this Java keyword as the return type.

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

    Rate this question:

  • 6. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 7. 

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

    • A.

      The data type of the parameter followed by the size of the parameter

    • B.

      The data type of the parameter followed by the name of the data type

    • C.

      The data type of the parameter followed by the name of the parameter

    • D.

      The name of the parameter followed by the data type of the parameter

    Correct Answer
    C. The data type of the parameter followed by the name of the parameter
    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.

    Rate this question:

  • 8. 

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

    • A.

      Must be coded in the same sequence and can have any data type

    • B.

      Must be coded in the same sequence and have the same data types as the parameters

    • C.

      Can be coded in the any sequence as long as they have the same data types as the parameters

    • D.

      Can be coded in any sequence and can have any data type parameters

    Correct Answer
    B. Must be coded in the same sequence and have the same data types as the parameters
    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.

    Rate this question:

  • 9. 

    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?

    • A.

      InitializeVariables;

    • B.

      InitializeVariable (int num);

    • C.

      InitializeVariables(void);

    • D.

      InitializeVariables();

    Correct Answer
    D. InitializeVariables();
    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.

    Rate this question:

  • 10. 

    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.

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 11. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 12. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 13. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 14. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 15. 

    A class can't have more than one constructor.

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 16. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 17. 

    A constructor automatically execute when a class object is instantiated.

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 18. 

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

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

    Rate this question:

  • 19. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 20. 

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

    Correct Answer
    inner classes
    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.

    Rate this question:

  • 21. 

    In Java Arrays are objects.

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 22. 

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

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

    Rate this question:

  • 23. 

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

    • A.

      0

    • B.

      1

    • C.

      10

    • D.

      Not Defined

    Correct Answer
    D. Not Defined
    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.

    Rate this question:

  • 24. 

    When Arrays are passed a parameter to a method they are passed as:

    • A.

      By Reference which allows the contents of the array to be changed and reflected back in the called area of the code.

    • B.

      Indirectly which allows the contents of the array to be changed and reflected back in the called area of the code.

    • C.

      By Reference which allows the contents of the array to be changed but they are not reflected back in the called area of the code.

    • D.

      By Reference which does not allow the contents of the array to be changed or reflected back in the called area of the code.

    Correct Answer
    A. By Reference which allows the contents of the array to be changed and reflected back in the called area of the code.
    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.

    Rate this question:

  • 25. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 26. 

    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.

    Correct Answer
    private String[] getValues()
    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.

    Rate this question:

  • 27. 

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

    • A.

      4

    • B.

      5

    • C.

      45

    • D.

      20

    Correct Answer
    D. 20
    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.

    Rate this question:

  • 28. 

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

    • A.

      4

    • B.

      5

    • C.

      45

    • D.

      20

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

    Rate this question:

  • 29. 

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

    • A.

      4

    • B.

      5

    • C.

      45

    • D.

      20

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

    Rate this question:

  • 30. 

    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:

    Correct Answer
    iArrNumbers[1][2]
    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.

    Rate this question:

  • 31. 

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

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

    Rate this question:

  • 32. 

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

    Correct Answer
    superclass
    parent class
    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.

    Rate this question:

  • 33. 

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

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

    Rate this question:

  • 34. 

    This Java keyword calls the constructor in the parent class.

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

    Rate this question:

  • 35. 

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

    Correct Answer
    subclass
    child class
    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.

    Rate this question:

  • 36. 

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

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

    Rate this question:

  • 37. 

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

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

    Rate this question:

  • 38. 

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

    Correct Answer
    Encapsulation
    Inheritance
    Polymorphism
    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.

    Rate this question:

  • 39. 

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

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

    Rate this question:

  • 40. 

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

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

    Rate this question:

  • 41. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 42. 

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

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

    Rate this question:

  • 43. 

    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.

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

    Rate this question:

  • 44. 

    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.

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

    Rate this question:

  • 45. 

    What object does every class ultimately inherit from in Java?

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

    Rate this question:

  • 46. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

Quiz Review Timeline +

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

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.