Java SE 11: Encapsulation Flashcards
static is a ______ that we apply to a method or a variable
modifier
_____ means that the method or variable belongs to the class and is shared by all objects in that class
static
a static modifier means it’s not unique to an object instance, and it can be accessed without _________ the class. So we don’t need to use the ___ keyword, and no constructor gets called when we access static methods or variables
a static modifier means it’s not unique to an object instance, and it can be accessed without instantiating the class. So we don’t need to use the NEW keyword.
A constructor gets called when we access static methods or variables.
True or False
False
You don’t need to use the new keyword, and no constructor gets called when we access static methods or variables
An _______ vairable is unique to an individial object
Instance
In the following ItemSizes class does a ItemSizes object need to be instatied in order to access it’s members?
Yes or No
public class ItemSizes {
public static String mSmall = “Mens Small”
}
}
No
since the member is static it can be accessed without having to create the ItemSizes class
an ______ _____ is a non-static method
instance method
Is the setSize() method an instance method or static method?
public class Item {
public String size;
public void setSize(String sizeArg) {
size = sizeArg;
}
}
Instance method
How do you make a variable a constant?
using the final keyword before the variable type name
ex. final int COLUMNS
constant variables can be changed after they have been initialized.
True or False
False
Constants cannot be changed after they have been initialzed.
The name of variables declared class ______ should always be uppercase
constants
What is called when the compiler changes the type of variable to a type that supports a larger size?
Promotion
Some promotions are done automatically by the compiler
True or False
True
Feature of promotion is to avoid ________ values.
Truncated
We use ____ _______ to lower the range of a value
type casting