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 Bing22
B
Bing22
Community Contributor
Quizzes Created: 3 | Total Attempts: 4,724
| Attempts: 1,436 | Questions: 38
Please wait...
Question 1 / 38
0 %
0/100
Score 0/100
1.  Which of the following does not contribute to improved software reusability?

Explanation

Quickly creating new class libraries without testing them thoroughly does not contribute to improved software reusability because without thorough testing, there is a higher chance of introducing bugs or errors in the library. This can lead to unreliable or unstable code, making it difficult to reuse the library effectively. Testing is crucial to ensure the quality and reliability of the software components being reused, and skipping this step can hinder the reusability of the code.

Submit
Please wait...
About This Quiz
Object Oriented Programming Quizzes & Trivia

This 'ch8 java' quiz assesses key concepts in Java class design, including public interfaces, method functionalities, and access modifiers. It evaluates understanding of static methods, private variables, and the use of 'this' reference, essential for anyone learning Java programming.

Tell us your name to personalize your report, certificate & get on the leaderboard!
2. Which of the following statements is true?

Explanation

The statement "Methods and instance variables can both be either public or private" is true. In object-oriented programming, methods and instance variables can have different access modifiers such as public or private. Public members can be accessed by any class, while private members can only be accessed within the same class. This allows for information hiding and encapsulation, as private members are not directly accessible to the client of a class. Therefore, the correct answer is that methods and instance variables can be either public or private.

Submit
3.  What happens when this is used in a constructor’s body to call another constructor of the same class if that call is not the first statement in the constructor?

Explanation

When using "this" in a constructor's body to call another constructor of the same class, it is necessary for this call to be the first statement in the constructor. If it is not, a compilation error occurs. This is because the first statement in a constructor should always be either a call to another constructor in the same class or a call to the superclass constructor. If "this" is used to call another constructor, it must be the first statement to ensure proper initialization of the object.

Submit
4.  The term “information hiding” refers to:

Explanation

The term "information hiding" refers to the practice of concealing the internal workings and implementation details of a class from its clients. This is done to promote encapsulation and abstraction, allowing the class to change its implementation without affecting the clients that use it. By hiding implementation details, the class provides a clear and simplified interface to its clients, reducing complexity and improving maintainability.

Submit
5.  Which syntax imports all static members of class Math?

Explanation

The correct answer is "import static java.lang.Math.*". This syntax imports all static members of the class Math. The "import static" statement allows us to access static members of a class without specifying the class name each time. In this case, it imports all static members of the Math class, which includes mathematical functions like sqrt(), sin(), cos(), etc.

Submit
6.  Instance variables declared final do not or cannot:

Explanation

Instance variables declared final cannot be modified once they have been initialized. Once a final variable has been assigned a value, it cannot be changed. This ensures that the value of the variable remains constant throughout the program execution. Declaring a variable as final also prevents any accidental changes to its value, providing a level of safety and immutability to the variable. Therefore, the correct answer is that final instance variables cannot be modified.

Submit
7. Which of the following should usually be private?

Explanation

Variables (or fields) should usually be private because it helps to encapsulate the data within a class and prevent direct access from outside. This allows for better control over the data and ensures that it is accessed and modified only through the methods provided by the class. By keeping variables private, it also helps to maintain the integrity of the data and avoid unintended modifications or inconsistencies. On the other hand, methods and constructors can have different levels of access depending on the specific requirements of the class.

Submit
8.  Composition is sometimes referred to as a(n) ________.

Explanation

Composition is a relationship between two classes, where one class contains an instance of another class as a member variable. This is known as a "has-a" relationship because one class "has" another class as a part of its structure. In composition, the lifetime of the contained object is dependent on the lifetime of the container object.

Submit
9. : enum types are implicitly ________ and enum constants are implicitly ________.

Explanation

Enum types are implicitly final, meaning they cannot be extended or subclassed. Enum constants, on the other hand, are implicitly static, meaning they belong to the enum type itself rather than to any particular instance of the enum. This allows enum constants to be accessed without the need to create an instance of the enum type.

Submit
10. 8.5 Q2: Constructors:

Explanation

The explanation for the given correct answer is that constructors are used to initialize instance variables, which means they are responsible for assigning initial values to the variables of an object. When constructors are overloaded, it means that there are multiple constructors with the same name but different parameters. In such cases, the constructor to be called is selected based on the number, types, and order of the parameters provided. Therefore, the correct answer is a and c.

Submit
11.  A constructor cannot:

Explanation

A constructor is a special method that is used to initialize objects of a class. It has the same name as the class and is called automatically when an object is created. Unlike regular methods, constructors do not have a return type or return values. Their purpose is to initialize the variables of the object to their default values or to values specified by the programmer. Overloading a constructor means having multiple constructors with different parameters, allowing for different ways to create objects of the class. Therefore, the correct answer is that a constructor cannot specify return types or return values.

Submit
12. When implementing a method, use the class’s set and get methods to access the class’s ________ data.

Explanation

When implementing a method, it is recommended to use the class's private data. This is because private data can only be accessed within the class itself, ensuring encapsulation and data integrity. Using the class's set and get methods to access the private data allows for controlled and validated access, maintaining the class's internal state and preventing direct manipulation of the data by external entities.

Submit
13. Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods.

Explanation

Set methods are commonly known as mutator methods because they are used to modify or change the values of an object's attributes. These methods typically take parameters that represent the new values to be assigned to the attributes. On the other hand, get methods are commonly known as accessor methods because they are used to retrieve or access the values of an object's attributes. These methods typically do not take any parameters and simply return the current values of the attributes.

Submit
14.  A programmer-defined constructor that has no arguments is called a ________.

Explanation

A programmer-defined constructor that has no arguments is called a no-argument constructor. This type of constructor is used to create objects without passing any arguments to initialize the object's state. It is commonly used when the object's initial state can be set to default values or when the values will be set later using setter methods.

Submit
15.  A class within a package must be declared public if

Explanation

When a class within a package needs to be used by classes that are not in the same package, it must be declared as public. This allows other classes outside of the package to access and use the class. By declaring the class as public, it becomes visible to other packages and can be utilized as needed.

Submit
16.  The import declaration import *; ________.

Explanation

The import declaration "import *;" causes a compilation error because the asterisk (*) is not a valid syntax for importing all classes in a library. The correct syntax for importing all classes is "import library.*;".

Submit
17. Which statement is false?

Explanation

The statement "The compiler always creates a default constructor for a class" is false. The compiler only creates a default constructor if no other constructors are explicitly defined in the class. If the class has any constructor with arguments, the compiler will not create a default constructor. Therefore, if a program attempts to call a no-argument constructor for a class that only has constructors with arguments, a compilation error will occur.

Submit
18.  Java programmers do not focus on:

Explanation

Java programmers do not focus on understanding class library implementations. While they may craft new classes, reuse existing classes, test and document their own classes, their main focus is not on understanding how the class library is implemented. The class library is a collection of pre-written classes and methods that programmers can use to build their applications. Java programmers rely on the class library to provide functionality and do not necessarily need to understand the inner workings of the library itself.

Submit
19. The static method ________ of class String returns a formatted String.

Explanation

The static method "format" of class String returns a formatted String. This method allows you to specify a format string and a variable number of arguments, which will be inserted into the format string in the specified positions. The format method is commonly used for formatting strings with placeholders, such as "%d" for integers or "%s" for strings, and then replacing those placeholders with the actual values provided as arguments.

Submit
20. A package is:

Explanation

The correct answer is "All". A package is all of the above - it is a directory structure used to organize classes and interfaces, a mechanism for software reuse, and a group of related classes and interfaces. Packages help in organizing code, promoting reusability, and providing a logical structure to the project.

Submit
21. Which method returns an array of the enum’s constants?

Explanation

The "values" method returns an array of the enum's constants. This method is automatically generated by the compiler when an enum is defined. It allows you to access all the constants of the enum in a convenient way.

Submit
22. The classpath consists of a list of directories or archive files, each separated by a ________ on Windows or a ________ on UNIX/Linux/Max OS X.

Explanation

The classpath consists of a list of directories or archive files, each separated by a semicolon (;) on Windows or a colon (:) on UNIX/Linux/Max OS X.

Submit
23. Using public set methods provides data integrity if:

Explanation

Using public set methods provides data integrity if the instance variables are private and the methods perform validity checking.

If the instance variables are private, it means that they cannot be directly accessed or modified from outside the class. This ensures that the data remains encapsulated and can only be accessed through the set methods.

Additionally, if the set methods perform validity checking, it means that they validate the data before setting it. This helps to ensure that only valid data is stored in the instance variables, maintaining data integrity.

Therefore, both conditions (b and c) are necessary for using public set methods to provide data integrity.

Submit
24. Having a this reference allows:

Explanation

The correct answer is "All of the above." Having a "this" reference in a method allows all of the mentioned options. It allows the method to refer explicitly to the instance variables and other methods of the object on which the method was called. It also allows the method to refer implicitly to the instance variables and other methods of the object on which the method was called. Additionally, it allows an object to reference itself.

Submit
25. Static class variables:

Explanation

Static class variables are shared by all objects of a class, meaning that they are not specific to any particular instance of the class. This means that any changes made to a static variable will be reflected across all instances of the class. Static variables are not unique to each object and can be accessed and modified by any object of the class.

Submit
26. Abstract Data Types:

Explanation

The answer "All of the above" is correct because abstract data types do elevate the importance of data by providing a way to organize and manipulate it effectively. They are also approximations or models of real-world concepts and behaviors, as they represent and mimic real-world entities and their interactions. Additionally, abstract data types capture two notions: data representation, which defines how the data is structured and stored, and operations, which define the actions that can be performed on the data. Therefore, all the statements mentioned in the options are true.

Submit
27. A final field should also be declared ________ if it is initialized in its declaration.

Explanation

A final field should also be declared as static if it is initialized in its declaration. This is because a final field is a constant and cannot be changed once it is assigned a value. By declaring it as static, the field becomes a class-level variable that is shared among all instances of the class. This ensures that the value of the final field is consistent across all instances and can be accessed without creating an instance of the class.

Submit
28. When compiling a class in a package, the javac command-line option ________ causes the javac compiler to create appropriate directories based on the class’s package declaration.

Explanation

The javac command-line option "-d" is used to specify the directory where the compiled class files should be placed. When compiling a class in a package, this option causes the javac compiler to create appropriate directories based on the class's package declaration. This ensures that the compiled class file is placed in the correct directory structure that matches the package structure.

Submit
29. When no access modifier is specified for a method or variable, the method or variable:

Explanation

When no access modifier is specified for a method or variable, it means that the method or variable has package access. This means that it can be accessed within the same package but not from outside the package. It is not public, private, or static, but rather has a default level of access within its package.

Submit
30. 8.2 Q1: The _________ of a class are also called the public services or the public interface that the class provides to its clients.

Explanation

The public methods of a class are the functions or operations that the class provides to its clients. These methods can be accessed and used by other classes or objects to interact with the class and perform certain actions or operations. They form the public interface of the class, allowing clients to utilize the functionality provided by the class. Therefore, the correct answer is "public methods".

Submit
31. Which statement is false?

Explanation

The statement "Clients are usually involved in a class’s implementation" is false. Clients are typically not involved in a class's implementation. The purpose of encapsulation is to hide the implementation details from the clients so that they can use the class without needing to know how it is implemented. Clients only need to know what the class does, not how it does it. Involving clients in the implementation would break the principle of encapsulation and increase the dependency on implementation details.

Submit
32.  Consider the statement

    package com.deitel.jhtp6.ch08;

    Which of the following is true?

Explanation

The given statement "package com.deitel.jhtp6.ch08;" uses the Sun Microsystems convention of package naming. This convention suggests that the package name should be in reverse domain name format, starting with a top-level domain such as com, followed by subsequent levels of the domain, and ending with the specific package name. In this case, the package name suggests that it belongs to the Deitel company and is related to the Java How to Program (jhtp6) book, specifically chapter 8.

Submit
33.  Which statement is false?

Explanation

An enum constructor cannot be overloaded means that it is not possible to have multiple constructors with different parameters in an enum. This is because enum constants are predefined and the constructor is called automatically when an enum constant is created. Therefore, there is no need for overloading the constructor in an enum.

Submit
34. Which of the following is false?

Explanation

The incorrect statement is "Objects are marked for garbage collection by method finalize." In Java, objects are not marked for garbage collection by the finalize method. Instead, the garbage collector determines which objects are eligible for garbage collection based on their reachability. The finalize method is used for performing cleanup actions on an object before it is garbage collected, but it does not directly mark the object for garbage collection.

Submit
35. Which of the following is false?

Explanation

A static method can call instance methods directly. This is true because a static method can access and call any instance method of its class, as long as it has access to an instance of that class.

Submit
36. When should a program explicitly use the this reference?

Explanation

The this reference should be explicitly used when accessing a local variable. The this keyword is used to refer to the current object, and it can be used to differentiate between a local variable and an instance variable with the same name. By using this, the program can access the local variable specifically associated with the current object.

Submit
37. The import declaration import java.util.*; is known as a ________.

Explanation

The import declaration "import java.util.*;" is known as a type-import-on-demand declaration because it allows all types in the "java.util" package to be imported into the current source file. This means that any class, interface, or enum within the "java.util" package can be used without having to specify the package name every time.

Submit
38.  By default, the classpath consists only of the ________. However, the classpath can be modified by providing the ________ option to the javac compiler.

Explanation

The classpath is a parameter that tells the Java Virtual Machine (JVM) where to look for classes and packages. By default, the classpath consists of the current directory. However, it can be modified by providing the -classpath option to the javac compiler. This allows developers to specify additional directories or JAR files to be included in the classpath. Therefore, the correct answer is current directory, -classpath.

Submit
View My Results

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

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

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 12, 2010
    Quiz Created by
    Bing22
Cancel
  • All
    All (38)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
 Which of the following does not contribute to improved software...
Which of the following statements is true?
 What happens when this is used in a constructor’s body to call...
 The term “information hiding” refers to:
 Which syntax imports all static members of class Math?
 Instance variables declared final do not or cannot:
Which of the following should usually be private?
 Composition is sometimes referred to as a(n) ________.
: enum types are implicitly ________ and enum constants are implicitly...
8.5 Q2: Constructors:
 A constructor cannot:
When implementing a method, use the class’s set and get methods to...
Set methods are also commonly called ________ methods and get methods...
 A programmer-defined constructor that has no arguments is called...
 A class within a package must be declared public if
 The import declaration import *; ________.
Which statement is false?
 Java programmers do not focus on:
The static method ________ of class String returns a formatted String.
A package is:
Which method returns an array of the enum’s constants?
The classpath consists of a list of directories or archive files, each...
Using public set methods provides data integrity if:
Having a this reference allows:
Static class variables:
Abstract Data Types:
A final field should also be declared ________ if it is initialized in...
When compiling a class in a package, the javac command-line option...
When no access modifier is specified for a method or variable, the...
8.2 Q1: The _________ of a class are also called the public services...
Which statement is false?
 Consider the statement    package...
 Which statement is false?
Which of the following is false?
Which of the following is false?
When should a program explicitly use the this reference?
The import declaration import java.util.*; is known as a ________.
 By default, the classpath consists only of the ________....
Alert!

Advertisement