Java Objects and Classes

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Random class

- this class provided by Java is used to generate random numbers - part of the java.util package

Constructor

A __ must have the same name as the class itself. __ do not have a return type - not even void. __invoked using the new operator when an object is created. If none are explicitly defined, a default ___ is made.

Immutable Class

A class without a mutator (set) method and data fields are private.

Instance or Static?

A variable or method that is dependent on a specific instance of the class should be an instance variable or method. A variable or method that is not dependent on a specific instance of the class should be made static, with class scope.

instance method

An object is called an instance. Therefore, the method of the object is called a ___ ___. Same applies for the variable; nonstatic because they depend on a reference variable.

Date class

Built-in JavaScript class that contains methods and properties for manipulating date and time.

Class notes

Class notes

Array of Objects

Class[] arrayName = new Class[#]

Circle Class example

Contains instance variable, radius() Instance methods: getArea(), getPerimeter().

TV Class Example

Example

TV Class, Main

Example

new

Instantiate an object using the ___ keyword, just like when instantiating an array; aka invoking the constructor

True

It's possible to add a Main class within a Public Class (T or F)

Passing an object to a method

Method parameter must have the Class name in it. public static void doSomething(Circle s){ c.setRadius = 5; c.getRadius(); }

True, True

Only one Public class per program (T or F) A separate file is generated per class in the program. (T or F)

get() and set()

Public methods used to retrieve and modify the private data fields.

data field encapsulation

Term used to set all data fields as private to prevent users from modifying the class data fields. However, data fields can be retrieved using the get() method.

dot operator (.)

The message-passing operator; can be used to utilize an object's state/data field or behavior/method. objectRefVar.dataField objectRefVar.method(arguments)

public

Use the ___ access modifier for classes, methods, and data fields to permit access from any OTHER CLASS AND PACKAGE.

private

Use the ___ modifier making methods and data fields accessible only from within their own class

Public and Private

What are the two main access modifiers? If neither is stated, default is public only within the package. (pg. 345 excellent diagram).

reference variable

___ stores the memory address of an object. Therefore, any change to this variable changes the contents of it's memory location. Robot x = new Robot(); x is what type of variable? Int[] anArray = new Int[25]; anArray is what type of variable?

instance variable (nonstatic)

a variable defined in a class for which every object of the class has its own value An independent variable for each instance of a class For example: Circle one = new Circle(4); instance radius 4 is independent of object 'two'. Circle two = new Circle(5);

static variable (aka class variable)

a variable defined in a class that has only one value for the whole class, shared by all objects, which can be accessed and changed by any method of that class Class Scope If one object changes this variable, then all objects are affected. Static variables share the same memory location by all objects of the same class. For example, used to store the # of objects instantiated.

this reference

an automatically created variable that holds the address of an object and passes it to an instance method whenever the method is called a reference to an object that is passed to any object's nonstatic class method ___ keyword refers to the calling object memory reference that invokes the instance method


Ensembles d'études connexes

Que, Quien, Lo que, and Cuyo & Cual

View Set

Life Insurance - Chapter 2 - Types Of Life Policies

View Set

Chapter 13: Monopolistic Competition

View Set

Qu'est-ce que tu fais sur Internet?

View Set