Level 103 Level 105
Level 104

[Quiz] Object & Classes


114 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 is a Class?
A blueprint of an object that defines all the variables and methods common to all the objects of a certain type.
What is an instance of a class?
When you construct an object from a class it's an instance
Dependence (uses-a)
What are the 3 most common relationships between classes?
What does public access mean on a method?
Any method in any class in the package can call the method
What does private access mean on an instance variable?
Only methods that can access the instances fields are in the class itself
using the same name as the class.
How is the constructor named in a class?
public className(......)
What is the basic syntax of a constructor?
Best practice is NO
Can a constructor have return values?
Only using the 'new' operator.
How can a constructor be called?
What classes or methods can access a private method?
Only the methods in the class itself. No outside access
It must be set with the constructor and becomes immutable.
When an instance variable is marked 'private final' what does that mean.
How can 'private' instance variables be changed?
Only through accessor and mutator methods of the class
If an instance variable is marked private final is constant?
No, it just means once set in the constructor it cannot be changed for that instance of the class.
What's the purpose of a static field in a class
It is used by all instances of the class to set a value. For example if you want to keep track of employee ids, set a private static nextID field to use as basis
Explain private static final variable
It's an instance variable used by all instances of the a class but the value is set and cannot be changed by any instances.
Only static fields
What kind of fields can a static method access
A problem domain
Objects model objects from.
Classes
represent all objects of a kind, define what fields an object has but each object stores its own set of values (the state of the object).
Abstraction
An abstract method is a method that is declared without implementation (no braces).
Invoke methods
The act of communicating with objects.
Methods
It is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
parameters
public static void main(int hello, String name){}
signature
The header of a method is called its signature. It provides information needed to invoke that method.
Data types
Describes the type of information stored in a variable or object.
state
Real world objects contain _______ and behavior.
fields
And object stores it states in _______.
Method-calling
Describes objects communicating by calling each other's methods.
Source Code
The source code of a class determines the structure and behavior (the fields and methods) of each of the objects of that class.
Return value
methods enable us to get information from an object via a method call (we can use methods either to change an object's state or to find out about its state).
How is a constructor instantiated?
className objectName = new className(value, value);
className.variable = 100;
How are variables and methods accessed from objects?
What happens if an object variable is assigned to another?
It gains all of the assigned object's variable values and methods.
public, protected, private, and default (no modifier)
What are the 4 access modifiers in Java?
public access modifier?
Can be accessed from anywhere essentially even outside the same package.
default (no modifier) access modifier?
Can be accessed from any other class in the same package.
private access modifier?
Can only be accessed from in the same class.
protected access modifier?
Can be accessed by subclasses and classes in the same package.
They are pass my reference
How are objects passed to methods and are they pass by reference or value?
className[] objectArrayName = new className[SIZE];
How is an array of objects created?
public class name EXTENDS superclass
How is extends used for inheritance?
How are methods and variables overridden with inheritance?
Just create methods/variables of the same name in the subclass. These will overwrite those inherited from the superclass
public constructor(int name)
How is the this keyword used when data field names conflict with method/Constructor parameters?
State and Behavior
2 Characteristics of Objects
State: current gear, speed
State the 2 object characteristics of a bicycle
fields (variables)
A software object's state is stored in ?
methods (functions)
A software object's behavior is exposed through
Define: Data Encapsulation
Hiding internal data from the outside world and accessing it only through publicly exposed methods
Define: Class
A blue print of a software object
Define: Super Class and Subclass.
Common behavior of a set of objects is defined in Superclass and inherited into a Subclass of those objects.
Define: Interface
A collection of methods that has no implementation. Ex: method(change gear); method(changespeed)
Define: Package
A namespace that organizes interfaces by functionality (like folders) /class library - API
Application Programming Interface
What does the term API stand for?
instantiation
creating an object with the "new" operator, eg. str1 = new String("hello");
class
All Java methods must be contained in a ...
identity, state, behavior
three main characteristics of objects
object
instance of a class. A software bundle of related variables and methods used to model real world objects. It has 2 defining characteristics - STATE and BEHAVIOR. State is stored as variables and behavior is represented using methods
static
Indicates that a variable or method belongs to a class, rather than to any object created from the class.
constructor
Used to instantiate (create) an object of that class
class description
used when an object is created
dot notation
accesses members (variables and methods) of an object, eg. len = str1.length();
library classes
allow you to use prewritten code/classes/toolkits/packages
field
A software object's state is stored in a
private methods
can be called only from constructors or methods of the same class
public methods
can be called from constructors or methods of any class
inheritance
allows a class to be a subclass of a superclass and thereby inherit public and protected variables and methods of the superclass. A parent/child relationship.
encapsulation
helps hide implementation behind an interface or API
Encapsulation helps ...
hide implementation details behind an interface (or API).
inheritance.
IS-A refers to ...
extends.
IS-A is expressed with the keyword ...
composition.
HAS-A refers to ...
HAS-A means ...
an instance of one class "has a" reference to an instance of another class or another instance of the same class.
inherit public and protected variables and methods of the superclass.
Inheritance allows a class to be a subclass of a superclass, and thereby ...
IS-A, polymorphism, overriding, overloading, and casting.
Inheritance is a key concept that underlies ...
All classes (except class Object), are ...
subclasses of type Object, and therefore they inherit Object's methods.
Polymorphism means ...
many forms, in other words subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class.
During runtime, only overridden instance methods are ...
dynamically invoked based on the real object's type.
overridden and overloaded.
Methods can be ...
Abstract method must be ...
overridden by the first concrete (non-abstract) subclass.
overridden.
Final methods cannot be ...
Only inherited methods can be ...
overridden, and remember that private methods are not inherited.
Overloading means ...
reusing a method name, but with different arguments.
overloaded in a subclass.
Methods from a superclass can be ...
which overridden method is used at runtime.
Object type (not the reference variable's type), determines ...
Reference type determines ...
which overloaded method will be used at compile time.
downcasting and upcasting.
There are two types of reference variable casting: ...
Downcasting is when ...
you can assign a reference variable that refers to a supertype object to a reference variable of the subtype but you must make an explicit cast to do this, and the result is that…
Upcasting is when ...
you can assign a reference variable that refers to a subtype object to a supertype reference variable explicitly or implicitly. This is an inherently safe operation because the assignment restricts the access capabilities of the new variable.
You implement an interface by properly and concretely ...
overriding all of the methods defined by the interface.
many interfaces.
A single class can implement ...
A constructor is always ...
invoked when a new object created.
a constructor called.
Each superclass in an object's inheritance tree will have ...
at least one constructor.
Every class, even an abstract class, has ...
Constructors must have ...
the same name as the class.
Return type
Constructors don't have a ...
Constructors can use ...
any access modifier (even private!).
The compiler will create ...
a default constructor if you don't create constructors in your class.
The default constructor is ...
a no-arg constructor with no-arg call to super().
The first statement of every constructor must be ...
a call to either this() (an overloaded constructor) or super().
the super constructor runs.
Instance members are accessible only after ...
called when a concrete subclass instantiated.
Abstract classes have constructors that are ...
constructors.
Interfaces do not have ...
A constructor can be ...
directly invoked only by another constructor (using a call to super() or this()).
All static members belong to ...
the class, not to any instance.
an instance variable directly.
A static method cannot access ...
Static methods can't be ...
overridden, but they can be redefined.
Coupling refers to ...
the degree to which one class knows about or uses members of another class.
Loose coupling is ...
the desirable state of having classes that are well encapsulated, minimize references to each other, and limit the breadth of API usage.
Tight coupling is ...
the undesirable state of having classes that break the rules of loose coupling.
Cohesion refers to ...
the degree in which a class has a single, well-defined role or responsibility.
High cohesion is ...
the desirable state of a class whose members support a single, well-defined role or responsibility.
Low cohesion is ...
the undesirable state of a class whose members support multiple, unfocused roles or responsibilities.
superclass subclass extends
common behavior can be defined in a _______ and inherited into a _______ using the _______ keyword
interface
What is a group of related methods with empty bodies?
package
What is a namespace containing an organized set of related classes and interfaces?