Level 104 Level 106
Level 105

[Quiz] Object & Classes II


94 words 0 ignored

Ready to learn       Ready to review

Ignore words

Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.

All None

Ignore?
What are primitives?
Primitives are the fundamental data type in Java.
What type of primitive data type is " int " ?
int is a primitive data type that is used to store integer values. It is the default value for whole numbers.
What is the "double " primitive type used to store and is it a default?
double is a primitive data type for large floating-point values. It is the default value for floating-point numbers.
What is a boolean primitive type used to store?
boolean is a primitive data type that is used to store true or false values.
What is the char primitive data type used to store?
char is a primitive data type that is used to store a single Unicode character.
What is the " byte " primitive used to store?
byte is a primitive used to store small numbers which are a byte (8 bits) or smaller.
What is the "short" primitive used to store?
short is a primitive used to store whole numbers up to 16 bits.
What is the "long" primitive used to store?
long is a primitive used to store large whole numbers up to 64 bits.
What is the "float" primitive used to store?
float is a primitive data type used to store floating-point values.
What case are primitive data types ?
Primitive data types all start with a lowercase letter, while classes start with an uppercase letter
Each primitive data type have a corresponding this?
The have a corresponding " Wrapper class "
What are objects and what defines them?
Objects are more advanced data types. They may be defined by a developer or found in a built-in Java package.
Chapter 4 Objective 2
Use Primitives, Enumerations, and Objects
How are Objects initialized?
Objects must be initialized by using the new keyword.
What does Arrays allow you to store?
Arrays allow you to store multiple variables together that can be accessed by an index.
Why Is Java considered a "strongly typed "language?
Java is a strongly typed language because Variables must be declared as a type, and any value that is stored must be compatible with this type.
Is it possible to cast a variable to a different data type?
It is possible to cast a variable to a different data type. If incompatible types are cast, an exception will be thrown.
What is a literal ?
A literal is a value that is hard-coded in code as the value itself.
What are the Java naming conventions that dictate how a "class" should be named?
Java naming conventions dictate that a class should be named with the first letter capitalized, along with each sequential word in the name.
What are the Java naming conventions that dictate how a "variable" should be named?
Java naming conventions dictate that a variable should be named with the first letter being lowercase, and with each sequential word in the name beginning with a capital letter.
_______
an object stores its state in
cadence
int cadence = 0;
public class MountainBike extends Bicycle{}
Program the public class MoutainBike that extends the class Bicycle.
private class MountainBike extends Bicycle {}
Program the private class MoutainBike that extends the class Bicycle.
public class MyClass {}
define a public class MyClass;
}
Define a class called MyClass that extends MySuperclass and implements Yourinterface.
subclass, YourInterface
class MyClass extends MySuperClass implements YourInterface {
private class Hello implements interface1,interface2{}
Define a private class Hello that implements the interfaces interface1 and interface2
integer
public int cadence;
modifier
public int cadence;
Acces modifier
public is called a:
private
In the spirit of encapsulation, it is common to make fields _______ .
verb
the first (or only) word in a method name should be a _______
yes
Is the "+" sign in front of numeric literals accepted by the compiler?
no
Can you change the size of an array once it's initialized?
No, Timer
Is timer a good classname?
No, EatDog
Is eatDog a good classname?
return 5.6;
public double calculateAnswer() {
Method Overloading
Different methods that have the same name but different argument lists.
Is this possible?
public class DataArtist {
Bicycle myBike = new Bicycle(30, 0, 8);
To create a new Bicycle object called myBike, a constructor is called by the new operator:
public Bicycle(int startCadence, int startSpeed, int startGear){}
Bicycle myBike = new Bicycle(30, 0, 8);
no-argument, superclass
You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors. This default constructor …
loanAmt, rate, futureValue
public double computePayment(double loanAmt, double rate, double futureValue,
array, objects
In this example, the method creates a new Polygon object and initializes it from an _______ of Point _______ (assume that Point is a class that represents an x, y coordinate):
array
public Polygon polygonFrom(Point... corners) {
corners
public Polygon polygonFrom(Point... corners) {
parameters, arguments,
_______ refers to the list of variables in a method declaration. _______ are the actual values that are passed in when the method is invoked. When you invoke a method, the arguments used must m…
parameter
Methods can have parameters to provide additional information for a task.
type
public Polygon polygonFrom(Point... corners) {}
Polygon, array.
public Polygon polygonFrom(Point[] corners) {
shadowing
public class Circle {
String[] args
public class PassPrimitiveByValue {
Int[] go
public class PassPrimitiveByValue {
3
public class PassPrimitiveByValue {
5
public class PassPrimitiveByValue {
undetermined
Point originOne;
declaring
type name;
reference
Objects, when passed as arguments, are passed by _______
(int a, int b)
public class Point {
same namem, return
You can recognize a constructor because its declaration uses the _______ as the class and it has no _______ type.
4
public class Rectangle {
number, type
The Java compiler differentiates the constructors based on the _______ and the _______ of the arguments.
no-argument constructor:
The Rectangle constructor used in the following statement doesn't take any arguments, so it's called a _______
no-argument, Object
The default constructor calls the class parent's _______ constructor, If the parent has no constructor (Object does have one), the compiler will reject the program.
default constructor.
If a class does not explicitly declare any constructor the Java compiler automatically provides a no-argument constructor, called the _______ .
no-argument, Object, reject
All classes have at least one constructor. If a class does not explicitly declare any, the Java compiler automatically provides a no-argument constructor, called the default constructor. This default constructor calls the class parent's no-argu…
Rectangle rectTwo;
rectTwo = new Rectangle();
object1.var1 = 1;
In the object "object1" is the variabele var1. Give it the value 1
No,
int height = new Rectangle().height;
recycled, Java Virtual Machine.
int height = new Rectangle().height;
references,scope ,null
An object is eligible for garbage collection when there are no more _______ to that object. References that are held in a variable are usually dropped when the variable goes out of _______. Or,…
periodically, memory
The Java runtime environment has a garbage collector that _______ frees the _______ used by objects that are no longer referenced.
A method returns to the code that invoked it when it
completes all the statements in the method, reaches a return statement, throws an exception
void
Every method should have a return type. If it doesn't return anything what is the return type?
public int returnNumber() {return 1;}
Type a public method returnNumber that returns the integer 1
Bicycle fastest;
public Bicycle seeWhosFastest(Bicycle myBike, Bicycle yourBike, Environment env) {
Bicycle myBike
public Bicycle seeWhosFastest(_______, Bicycle yourBike, Environment env) {
Bicycle
public _______ seeWhosFastest(Bicycle myBike, Bicycle yourBike, Environment env) {
fastest
public Bicycle seeWhosFastest(Bicycle myBike, Bicycle yourBike, Environment env) {
public ImaginaryNumber returnANumber() {}
Suppose that you have a class hierarchy:
covariant return type.
This technique, called _______, means that the return type is allowed to vary in the same direction as the subclass.
1
public class Point {
9
public class Point {
explicit constructor invocation
From within a constructor, you can also use the this keyword to call another constructor in the same class. Doing so is called an _______
this(0, 0, 0, 0);
public class Rectangle {
The act of calling upon a spirit by incantation.
Fun fact: What does invocation say in the dicionary?
top-level, member-level
Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control. At the _______ and at the_______ .
public, none
Access level modifiers at the top-level are:
public, private, protected, none
Access level modifiers at member level are:
private function1(){
Access level modifier.
package-private
function1(){
no modifier
Wich access modifier has acces to a: class, Package
protected
Wich access modifier has acces to a: class, Package, subclass