Questions and Answers
Due to automatic type promotion, when a method with a double parameter is passed an integer, the integer will be promoted to a(n) ____.
double
When you instantiate an object from a class, ____ is reserved for each instance field in the class.
memory
_____ variables are variables that are shared by every instantiation of a class.
class
When you multiply an int and a double, the result is the int.
Signup and view all the answers
The ____ statement notifies the program that you will be using the data and method names that are part of the imported class or package.
Signup and view all the answers
When you properly ____ a method, you can call it providing different argument lists, and the appropriate version of the method executes.
Signup and view all the answers
You can use ____ arguments to initialize field values, but you can also use arguments for any other purpose.
Signup and view all the answers
If you want all objects to share a single nonchanging value, then the field is static and ____.
Signup and view all the answers
If you give the same name to a class's instance field and to a local method variable, the instance variable overrides the method's local variable.
Signup and view all the answers
Match the following programming terms with their definitions:
Signup and view all the answers
You can use the asterisk (*) as a ____, which indicates that it can be replaced by any set of characters.
Signup and view all the answers
The reference to an object that is passed to any object's nonstatic class method is called the ____.
Signup and view all the answers
A variable comes into existence, or ____, when you declare it.
Signup and view all the answers
When an object of one class is a data field within another class, they are related by ______.
Signup and view all the answers
The compiler determines which version of a method to call by the method's ______.
Signup and view all the answers
If a class's only constructor requires an argument, you must provide an argument for every ____ of the class that you create.
Signup and view all the answers
The ____ package contains is implicitly imported into Java programs and is the only automatically imported, named package.
Signup and view all the answers
It is not necessary to create an instance of the Math class because the constants and methods of the class are ______.
Signup and view all the answers
Fields declared to be static are not always final.
Signup and view all the answers
An alternative to importing a class is to import an entire package of classes.
Signup and view all the answers
It is illegal to declare the same variable name more than once within a block.
Signup and view all the answers
A variable can hold more than one value at a time.
Signup and view all the answers
You use the ____ data type to hold any single character.
Signup and view all the answers
The int data type is the most commonly used integer type.
Signup and view all the answers
The ____ is the type to which all operands in an expression are converted so that they are compatible with each other.
Signup and view all the answers
Multiplication, division, and remainder always take place after addition or subtraction in an expression.
Signup and view all the answers
A data item is ____ when it cannot be changed while a program is running.
Signup and view all the answers
Each primitive type in Java has a corresponding class contained in the java.lang package. These classes are called ____ classes.
Signup and view all the answers
Which of the following statements is correct in terms of using the assignment operator?
Signup and view all the answers
Study Notes
Java Programming Concepts
- Automatic type promotion occurs when an integer is passed to a method that expects a double parameter, promoting the integer to a double type.
- Memory is allocated for each instance field of an object when instantiated from a class.
- Class variables are shared among all instances of the class, providing a common value.
- Multiplying an integer with a double does not result in an integer; the statement claiming this is false.
- The import statement is essential for using classes and methods from external packages in a program.
- Method overloading allows the same method name to be utilized with different argument lists for flexibility in method execution.
- Constructor arguments can initialize field values and serve other purposes in the class.
- Static fields that need to remain unchanging across instances should also be declared final.
- If a local method variable shares the same name as an instance variable, the instance variable takes precedence; the statement claiming otherwise is false.
Variable Terminology
- A variable comes into existence, or enters scope, when declared within its block.
- Composition is a relationship where an object of one class serves as a data field within another class.
- The method signature comprises the name and parameters of the method, guiding the compiler in method resolution.
- If a constructor requires an argument, all objects of that class must be provided with that argument when instantiated.
Java Package and Data Types
- The java.lang package is automatically imported in Java programs, making its classes available by default.
- The Math class methods and constants can be used without creating an instance since they are static.
- Static fields in a class are not restricted to being final; they can be modified.
- Importing an entire package allows access to its classes, serving as an alternative to importing individually.
Variable Rules and Data Handling
- A variable cannot be declared with the same name more than once within the same block; this is considered illegal.
- Each variable can hold a single value at a time, contrary to some misconceptions.
- The char data type is specifically used to represent a single character.
- The int data type is the most commonly used for integer representation in Java.
Expression Evaluation and Constants
- The unifying type is the type all operands in an expression get converted to make them compatible.
- In expression evaluations, multiplication, division, and remainder operations take precedence over addition and subtraction, making related claims false.
- A constant value remains unchanged throughout the program's execution.
- Each primitive data type in Java has a corresponding type-wrapper class, housed in the java.lang package.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
This quiz covers essential concepts in Java programming, including type promotion, memory allocation in classes, and method overloading. Understand how class and instance variables function and the importance of import statements in managing external packages. Test your knowledge on constructors and static fields as well.