Java Quizzes
A constructor can only be used to initialize the instance variables belonging to the new object.
False
A constructor signature always indicates a return type of String.
False
A for loop header consists of three clauses separated by colons.
False
A for loop is an exit condition loop.
False
A reference variable whose declared type is an array type contains space for the array components.
False
A single object in Java can be treated as only one type, which is the name of the class from which the object was instantiated.
False
A value of the type int may have a fractional part.
False
A value of type boolean can be assigned to a variable of type double.
False
A value of type double can be (almost) any numeric value, positive or negative, but it cannot have a fractional part.
False
All Java data types conceptually have something to do with numeric values or arithmetic.
False
All array objects have a size property that can be accessed to determine the number of elements in the array.
False
All array objects in Java encapsulate multi-dimensional arrays.
False
All classes in Java form a hierarchy with a class named Root at the root of the hierarchy. Thus, every class in Java is a direct or indirect subclass of the class named Root.
False
An array's length is part of its type or reference variable declaration.
False
An object has changed its state when one or more of the methods stored in the object have been modified.
False
An operator that operates on only one operand is called a binary operator.
False
Any method that is declared final can be overridden in a subclass.
False
Array indices always begin with 1.
False
Array objects in Java encapsulate a group of one or more variables
False
At any instant in time, the state of an object is determined by the values stored in its methods and its behavior is determined by its instance variables.
False
Because a for loop is an entry condition loop, the third clause inside the parentheses is executed at the beginning of each iteration.
False
Class variables and class methods are not declared static.
False
Class variables must be of a primitive type such as int or float.
False
Constructors cannot be overloaded.
False
Encapsulation is the concept that an object should totally totally expose its implementation in its interface.
False
Every object instantiated from a given class shares the same single copy of each instance variable declared in the class definition.
False
Given that the controlling class of every Java application must contain a mainmethod, other classes in the program may not also have a main method
False
Given: A Java program consists of one or more source code files. Each source code file can contain one or more class definitions. When the program is compiled, the output will consist of one file with an extension of .class for each source code file.
False
If a new class doesn't explicitly extend some other class, it will, by default, automatically extend the class named Root.
False
If an attempt is made to access the array with an invalid index value, a non-fatal warning is displayed.
False
If the Java application is not designed to use command-line arguments, it is not necessary to include a formal argument list for the main method.
False
If the behavior of one or more methods defined in a superclass and inherited into your new class is not appropriate for an object of your new class, you can change that behavior by overloading the method in your new class
False
If you don't define a constructor when you define a new class, your program will not compile.
False
If you have an instance of the byte type, the set of all possible values that you can store in that instance is the set of all the whole numbers ranging from -256 to +255.
False
In Java, a legal identifier is a sequence of ASCII letters and digits of unlimited length. The first character must be a letter. All subsequent characters must be letters or numerals from any alphabet that ASCII supports. In addition, the underscore character (_) and the dollar sign ($) are considered letters and may be used as any character including the first one.
False
In Java, local variables are declared outside the body of a method or constructor, and outside a block of code contained within the body of a method or constructor.
False
In Java, the assignment operator is the % character.
False
In Java, the class name alone is sufficient for accessing class variables and classmethods by joining the name of the class with the name of the variable or method using a colon.
False
In Java, you are required to initialize the value of all variables when they are declared.
False
In Java, you must write all of the methods that you need.
False
In Java, you usually represent a character in your program by surrounding it with quotation marks as shown below: "A"
False
In order for the System class to be useful to an application, the application must instantiate objects of the System class.
False
In order to understand OOP, you need to understand the following three concepts:
False
Instance variables and instance methods are declared static.
False
It is easy to write outside of the bounds of a String or an array.
False
It is required that you simultaneously declare the name of the variable and cause memory to be allocated to contain the array object in a single statement.
False
Java allows free-standing methods outside of a class definition
False
Java is not a case-sensitive programming language.
False
Java only allows you to use the pre-written methods in the standard class libraries.
False
Java provides two different string classes from which string objects can be instantiated. The two classes are: -String -StringWriter
False
Java stores variables of type char according to the 8-bit extended ASCII table.
False
Just as in other languages, when declaring a two-dimensional array in Java, it is necessary to declare the size of the secondary dimension when the array is declared.
False
Just as in other languages, when you create a multi-dimensional array, the secondary arrays must all be of the same size.
False
Method overloading is often referred to as run-time polymorphism.
False
Multi-line comments begin with /# and end with #/
False
Overloaded methods must have the same name, same return type, but different formal argument lists than the methods that they overload.
False
Overridden methods must have the same name and same formal argument listas the methods that they override but may have the same or a different return type.
False
Polymorphism manifests itself in Java in the form of multiple methods having different names.
False
Polymorphism manifests itself in Java in the form of multiple variables having the same name.
False
Relational operators return the double type in Java.
False
Run-time polymorphism is distinguished by the fact that the compiler selects a specific method from two or more overloaded methods on the basis of the types and the number of parameters passed to the method when it is called. The selection is made when the program is compiled (rather than being made later when the program is run).
False
Several methods are inherited from the Object class into all other classes. Those that are declared final may be overridden to make their behavior more appropriate for objects instantiated from the new class.
False
The Java Collections Framework operates independently of the use of interfaces.
False
The Java compiler will accept statements with type mismatches provided that a suitable type conversion can be implemented by the compiler at compile time.
False
The Object class defines default versions of several methods including a method named fromString.
False
The StringBuffer class is used for strings that are not allowed to change. The String class is used for strings that are modified by the program.
False
The comma operator guarantees that its right operand will be executed before its left operand.
False
The common name for the Java program element that is used to contain data that may change during the execution of the program is method
False
The constructor is called repeatedly during the lifetime of an object.
False
The expressions within the first clause in the parentheses in a for loop are executed once during each iteration of the loop.
False
The first string in the array of command-line arguments in the main method contains the name of the Java application
False
The implements keyword is used to extend an existing class into a new class.
False
The increment operator is a binary operator.
False
The integer indices of a Java array object always extend from 1 to n where n is the length of the array object.
False
The javadoc tool is a special program that is used to compile Java programs.
False
The main method cannot access the variables and methods of objects instantiated from other classes.
False
The main method must instantiate objects of other classes in order for the program to execute.
False
The out variable in the System class is of a primitive type.
False
The overall behavior of an object is determined by the total value of its data
False
The primitive types are not part of the core language.
False
The println method is an instance method of the System class.
False
The purpose of the toString method is to return a reference to an object of the class Image that contains an image of an object instantiated from a class that overrides the toString method.
False
The same syntax is required to create array objects as the syntax normally used to instantiate ordinary objects.
False
The second clause in the parentheses of a for loop consists of a single expression which must eventually evaluate to true to cause the loop to terminate.
False
The significance of an exit condition loop is that the conditional expression is tested before the statements in the loop are executed. If it tests false initially, the statements in the loop will not be executed.
False
The static keyword when used as the return type for any Java method indicates that the method does not return anything.
False
The super keyword cannot be used to cause a constructor in a subclass to call a parameterized constructor in the immediate superclass.
False
The syntax for a class definition in Java requires a semicolon following the closing curly bracket.
False
The this keyword cannot be used to make it possible for one overloaded constructor to call another overloaded constructor in the same class.
False
The use of the new operator is required for instantiation of objects of type String.
False
The void keyword is used to cause a variable or method to become a classvariable or class method in Java
False
Unlike ordinary objects, array objects are not accessed via references but instead are accessed directly.
False
Variables of type int can contain either signed or unsigned values.
False
When declaring an array reference variable, the square brackets [] must appear following the variable name.
False
When you declare a variable capable of holding a reference to an array object, the memory required to contain the array object is automatically allocated.
False
When you define a class that extends another class, an object instantiated from your new class will only contain the methods and variables defined in your new class.
False
With a floating point type, positive exponent values mean that the decimal point should be shifted to the left. Negative exponent values mean that the decimal point should be shifted to the right.
False
With regard to operator precedence, add and subtract have higher precedence than multiply and divide.
False
You can perform the following five operations with data of type short: -You can add them together. -You can subtract one from the other. -You can multiply one by the other. -You can divide one by the other. -You can apply the exponentiation operator to raise a value of type short to a power.
False
You cannot store references to objects instantiated from classes that you define in a reference variable of type Object.
False
You need a special IDE to write Java code.
False
A Java method can be thought of as a separate program module that has the ability to do something useful. Having written the method, you can make it available for use as a helper to your main program each time your main program needs to have that useful thing done.
True
A block of code is defined by enclosing it within curly brackets as shown below {...}
True
A class is a blueprint or plan from which many objects can be created or instantiated.
True
A constructor is code that assists in the creation of an object according to the plans contained in a class definition. The primary purpose of a constructor is to provide initial values for the new object, but the constructor is not restricted to that behavior alone.
True
A member variable is a member of a class (class variable) or a member of an object instantiated from that class (instance variable). It must be declared within a class, but not within the body of a method or constructor of the class.
True
A reference to an array object can also be assigned to a reference variable of type Object (note the absence of square brackets). Thus, any of the methods of the Object class can be called on a reference to an array object.
True
A reference to an array object can refer to different array objects (of the same element type and different lengths) at different points in the execution of a program.
True
A reference to any object can be assigned to a reference variable of the type Object, because the Object class is a superclass of every other class.
True
A return statement is used to terminate a method and (optionally) return a value to the calling method.
True
A software object is an instance of a class.
True
A string is commonly considered to be a sequence of characters stored in memory and accessible as a unit. Java implements strings using the Stringclass and the StringBuffer class.
True
A value of a particular type may be assignment compatible with variables of other types.
True
A value of the type int may not have a fractional part.
True
A while loop is an entry condition loop.
True
All of the software that you need to create, compile, and run Java programs is free.
True
All variables in Java must have a defined type. The definition of the typedetermines the set of values that can be stored in the variable and the operations that can be performed by or on the variable.
True
An Object-Oriented Program consists of a group of cooperating objects, exchanging messages, for the purpose of achieving a common objective.
True
An array element is accessed by an expression whose value is an array reference followed by an indexing expression enclosed by matching square brackets.
True
An instance variable or an instance method can only be accessed by using a reference to the object that owns it. Even then, it may or may not be accessible depending on the access modifier assigned by the programmer.
True
An object is a software construct that encapsulates data, and the ability to use or modify that data, into a software entity.
True
An object of type PrintStream is automatically instantiated when the Systemclass is loaded into an application.
True
An operator performs an action on operands.
True
Array objects can contain any Java data type including primitive values, references to ordinary objects, and references to other array objects.
True
Array objects with explicit initialization are created using a comma-separated list of expressions enclosed in curly brackets.
True
Arrays in Java are objects, which are dynamically created and allocated to dynamic memory.
True
As the computer program performs its calculations in the correct order, it is often necessary for it to store intermediate results someplace, and then come back and get them to use them in subsequent calculations later.
True
Because different classes can implement the same interface, objects instantiated from different classes can be treated as a common interface type.
True
Class methods can be called without the requirement to instantiate an object of the class
True
Class variables such as the out variable of the System class must be of some specific type.
True
Command-line-arguments are used in many programming and computing environments to provide information to the program at startup that it will need to fulfill its mission during that particular run.
True
During the execution of a while statement, the program will continue to execute the statement or compound statement for as long as the conditional expression evaluates to true, or until a break, continue, or return statement is encountered.
True
Every class in Java, (including new classes that you define), inherits the methods that are defined in the Object class.
True
For primitive types, performing a cast may result in the loss of information.
True
For purposes of discussion, primitive types can be subdivided into four categories: -Whole-number types -Floating-point types -Character types -Boolean types
True
Given that you must declare a variable capable of holding a reference to an array object before you can use the array, when declaring the variable, you must provide the following information: -the name of the variable -the type of the variable, which indicates the type of data to be stored in the array
True
If a class implements an interface, it must provide a concrete definition for all the methods declared by that interface, and all the methods inherited by that interface. Otherwise, the class must be declared abstract and the definitions must be provided by a class that extends the abstract class.
True
If not overridden, the default version of the toString method that is defined in the Object class returns a String object containing text similar to the following: NameOfClass@111f71
True
If the declared element type for the array object is one of the primitive types, the elements of the array can be used to store values of any primitive type that is assignment compatible with the declared type (without the requirement for a cast).
True
If the declared element type is an interface type, a null reference or a reference to any object instantiated from any class that implements the interface can be stored in the array element.
True
If the declared element type is the name of a class, (which may or may not be abstract), a null reference or a reference to any object instantiated from the class or any subclass of the class may be stored in the array element.
True
If the element type of an array object is Object, the elements in the array can refer to: -Other array objects -Ordinary objects -A mixture of the two
True
If the elements in an array are not purposely initialized when the array is created, the array elements will be automatically initialized with default values.
True
If the type of a value is not assignment compatible with a variable of a given type, it may be possible to assign it to the variable through the use of the cast operator
True
If you don't provide matching parentheses to control the order of evaluation, the order will be determined by the precedence of the operators with the operations having higher precedence being evaluated first. For example, multiply and divide have higher precedence than add and subtract.
True
In Java, syntax provisions must be made in the method signature for the mainmethod to accommodate command-line-arguments even if the remainder of the program is not designed to make use of them.
True
In Java, the name of a primitive variable evaluates to the value stored in the variable.
True
In Java, the name of a reference variable evaluates to either null, or to information that can be used to access an object whose reference has been stored in the variable.
True
In Java, the scope of a variable can be reduced by placing it within a block of code within the method. The scope extends from the point at which it is declared to the end of the block of code in which it is declared.
True
In Java, when using the assignment operator, the value stored in memory and represented by the right operand is copied into the memory represented by the left operand.
True
In a for loop, the first and third clauses within the parentheses can contain one or more expressions, separated by the comma operator.
True
In addition to state, objects exhibit behavior.
True
In order to use a reference of a given class type to call a method on an object, the method must be defined at or above that class in the class hierarchy.
True
Inheritance provides a formal mechanism for code reuse.
True
Instance variables and instance methods can only be accessed through an object of the class in Java.
True
It is Prof. Baldwin's opinion that from a good overall design viewpoint, class variables should be used very sparingly, if at all.
True
It is not always possible to perform a successful cast to convert the type of a reference. Whether or not a cast can be successfully performed depends on the relationship of the classes involved in the class hierarchy.
True
It is often appropriate to use static methods in your programs, provided there is no requirement for the method to remember anything from one call to the next. An appropriate example of a static method is the sqrt method of the Math class.
True
It is very often appropriate to use final static variables as constants in your programs. It is rarely appropriate to use non-final static variables in your programs.
True
Java data types can be subdivided into two major categories: -Primitive types -User-defined or reference types
True
Java is a type-sensitive language
True
Java is an extensible programming language, meaning that there is a core component to the language that is always available. Beyond the core component, different programmers can extend the language in different ways to meet their individual needs.
True
Java supports both primitive types and reference types.
True
Multi-dimensional arrays are not required to represent rectangles, cubes, etc. They can be ragged.
True
No matter how many objects are instantiated from a class definition, they all share a single copy of each class variable.
True
Once an array object is created, its type and length never changes.
True
Overloaded methods have the same name and different formal argument lists. They may or may not have the same return type. The return type is not a determining factor insofar as overloading is concerned.
True
Overloaded methods may all be defined in the same class, or may be defined in different classes as long as those classes have a superclass-subclass relationship in the class hierarchy.
True
Single-line comments begin with // and end at the end of the line.
True
String objects cannot be modified once they have been created but StringBuffer objects can be modified.
True
The Java class library contains a class named Object and another class named Class.
True
The Java compiler considers a series of characters surrounded by quotation marks to be a literal string, as in the following code fragment: "This is a literal string in Java."
True
The Object class is a completely generic type.
True
The Object class is the superclass of all other classes. Therefore, an array of element type Object is capable of storing references to objects instantiated from any other class. The type declaration for such an array object would be Object[].
True
The assignment operator is a binary operator.
True
The char type uses a standard character representation known as Unicode to represent up to 65,535 different characters.
True
The code in a constructor never contains a return statement.
True
The components in an array object may refer to other array objects. The number of bracket pairs used in the declaration of the reference variable indicates the depth of array nesting (in the sense that array elements can refer to other array objects).
True
The existence of static members tends to break up or complicate the simple OOP structures that were discussed earlier in this course.
True
The existing class is often called the superclass and the new class is often called the subclass. This is the mechanism for class inheritance in Java.
True
The implementation of interfaces in Java is similar to multiple inheritance in languages such as C++.
True
The main method in the controlling class of a Java application controls the flow of the program.
True
The most fundamental way to compile and run Java applications is from the command line.
True
The name instance variable comes from the fact that every instance of the class (object) has one.
True
The names of constructors must match the names of the classes in which they are defined.
True
The normal rules of type conversion and assignment compatibility apply when creating and populating array objects.
True
The number of command-line arguments entered at program startup is equal to the number of elements in the array of references to String objects referred to by args (or some other name) in the argument list for the main method. The number of elements is indicated by the value of the length property of the array. If the value is zero, the user didn't enter any command-line arguments.
True
The number of elements in the array is always available as a property named length.
True
The operation of a loop normally involves the following three actions in addition to executing the code in the body of the loop: -Initialize a control variable. -Test the control variable in a conditional expression. -Update the control variable.
True
The out variable in the System class refers to an instance of the PrintStreamclass (a PrintStream object), which is automatically instantiated when the System class is loaded into the application.
True
The overuse of static members can lead to problems similar to those experienced in languages like C and C++ that support global variables and global functions.
True
The println method can be accessed by joining the name of a variable that references a PrintStream object to the name of the println method using a period as the joining operator.
True
The println method causes its argument to be displayed on the standard output device.
True
The reason that the main method in a Java application must be declared static is because the static keyword indicates that the method is a class method which can be called without the requirement to instantiate an object of the class. This is used by the Java virtual machine to launch the program by calling the mainmethod of the class identified in the command to start the program.
True
The rules for Java variable names are as follows: -Must be a legal Java identifier consisting of a series of Unicode characters. -Must not be the same as a Java keyword and must not be true or false. -Must not be the same as another variable whose declaration appears in the same scope.
True
The scope of a Java variable is the block of code within which the variable is accessible.
True
The scope of a local variable extends from the point at which it is declared to the end of the block of code in which it is declared.
True
The scope of a method parameter is the entire method for which it is a parameter.
True
The scope of a variable places it in one of the following four categories: -member variable -local variable -method parameter -exception handler parameter
True
The single shared copy of a class variable or a class method can be accessed in either of two ways: Via a reference to any object instantiated from the class. By simply joining the name of the class to the name of the class variable or the class method. The variable or method may or may not be accessible, depending on the access modifiers assigned by the programmer.
True
The super keyword can be used to bypass a member variable in a subclass in order to access a member variable having the same name in a superclass.
True
The super keyword can be used to bypass the overridden version of a method in a subclass and execute the version in the superclass.
True
The syntax required to call a method on a Java object joins the name of the method to the object's reference, using a period as the joining operator.
True
The this keyword can be used to bypass local variables or parameters that hide member variables having the same name, in order to access the member variables.
True
The this keyword can be used to pass the current object's reference to a method belonging to a different object (as in implementing callbacks, for example).
True
The use of the new operator is required for instantiation of objects of type StringBuffer.
True
The values in the array elements may be purposely initialized when the array object is created using a comma-separated list of expressions enclosed by matching curly brackets.
True
The variables encapsulated in an array object don't have individual names. Rather, they are accessed using positive integer index values.
True
The whole-number types differ in terms of the range of values that they can accommodate and the amount of computer memory required to store instances of the types.
True
The word polymorphism means something like one name, many forms.
True
To override a method in your new class, simply reproduce the name, argument list, and return type of the original method in a new method definition in your new class.
True
To use a variable, you must notify the compiler of the name and the type of the variable (declare the variable).
True
Variables can be declared and initialized within the first clause in the parentheses of a for loop.
True
When an object responds to a message, it will usually perform an action, change its state, return a value, or some combination of the above.
True
When called, a method will usually -perform an action -send back an answer. or -some combination of the two
True
When declaring a reference variable capable of referring to an array object, the array type is declared by writing the name of an element type followed by some number of empty pairs of square brackets [].
True
When using command-line arguments in Java, if the name of the string array is args, the args.length attribute can be used by the code in the program to determine the number of arguments actually entered.
True
When you define a class that extends another class, the behavior of the methods defined in a superclass and inherited into your new class may, or may not, be appropriate for an object instantiated from your new class.
True
When you define a new class, you create a new type.
True
While the contents of a String object cannot be modified, a reference to a String object can be caused to point to a different String object.
True
With runtime polymorphism based on method overriding, the decision as to which version of a method will be executed is based on the actual type of the object whose reference is stored in the reference variable, and not on the type of the reference variable on which the method is called.
True
Wrapper classes are commonly used to convert variables of primitive types into true objects
True
You can call any of the methods defined in the Object class on any reference to any object stored in a reference variable of type Object.
True
You can control the order of evaluation of expressions in Java by the use of matching parentheses.
True
You can create a new class by extending an existing class.
True
The Object class defines default versions of several different methods. These methods are inherited into all other classes.
true