objects

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

If an objects does not need to be referenced later can create without explicitly assigning it to a variable. For instance new Circle(); This is called an _

Anonymous object

The variable myCircle can reference a Circle object. The next statement creates an object and assigns its redeems to myCircle

MyCircle = new Circle();

Constructors are invoked used the _ when an object is created

New operator

Runtime error that occurs when you invoke a method on a reference variable with a null value

NullPointerException

To prevent direct modifications of data fields, you should declare the data fields private, using the private modifier. This is known as _.

data field encapsulation

If a class is defined without the package statement, it is said to be placed in the __

default package

The program contains two classes. The first of these, TestSimpleCircle, is the main class. Its sole purpose is to test the second class, SimpleCircle. Such a program that uses the class is often referred to as _ of the class. When you run the program, the Java runtime system invokes the main method in the main class.

a client

To enable a private data field to be updated, provide a setter method to set a new value. A getter method is also referred to as an _ and a setter to a _.

accessor, mutator

Constants in a class are shared by all objects of the class. Thus, constants should be declared as __. For example, the constant PI in the Math class is defined as: _ double PI = 3.14159265358979323846;

final static

after the assignment statement c1 = c2, c1 points to the same object referenced by c2. The object previously referenced by c1 is no longer usefuland therefore is now known as garbage. Garbage occupies memory space, so the Java runtime system detects garbage and automatically reclaims the space it occupies. This process is called _.

garbage collection

A private data field cannot be accessed by an object from outside the class that defines the private field. However, a client often needs to retrieve and modify a data field. To make a private data field accessible, provide a __ to return its value.

getter method

TestPoint2D.java program start: import java.util.Scanner; _ public class TestPoint2D {

import javafx.geometry.Point2D;

Java supports static methods as well as static variables. Static methods can be called without creating an _of the class.

instance

Constructs a Date object for the current time.

+Date()

Constructs a Date object for a given time in milliseconds elapsed since January 1, 1970,GMT.

+Date(elapseTime: long)

Constructs a Point2D object with the specified x- and y-coordinates.

+Point2D(x: double, y: double)

Constructs a Random object with the current time as its seed.

+Random()

Constructs a Random object with a specified seed.

+Random(seed: long)

Returns the distance between this point and the specified point p.

+distance(p: Point2D): double (p1.distance(p2));)

Returns the distance between this point and the specified point (x, y).

+distance(x: double, y: double): double

Returns the number of milliseconds since January 1, 1970 GMT

+getTime(): long System.out.println("The elapsed time since Jan 1, 1970 is " + date.getTime() + " milliseconds");

Returns the x-coordinate from this point.

+getX(): double

Returns the y-coordinate from this point

+getY(): double

Returns a random boolean value

+nextBoolean(): boolean

Returns a random double value between 0.0 and 1.0 (excluding 1.0).

+nextDouble(): double

Returns a random float value between 0.0F and 1.0F (excluding 1.0F).

+nextFloat(): float

Returns a random int value.

+nextInt(): int

Returns a random int value between 0 and n (excluding n).

+nextInt(n: int): int

Returns a random long value

+nextLong(): long

Sets a new elapse time in the object.

+setTime(elapseTime: long): void

Returns a string representation for the point.

+toString(): String

Returns a string representing the date and time.

+toString(): String (System.out.println(date.toString());)

create a point2d object called p1

Point2D p1 = new Point2D(x1, y1);

A class is essentially a _, it is a _ which means that a variable of the class type can reference an instance of the class

Programmer defined type, reference type

Objects are accesses via the objects _ which contains reference to the objects

Reference variable

Constructors do not have a _ not even _

Return type, void

Constructor must have the _ as the _ itself

Same name, class

All method in the math class (Math.pow(3, 2.5) are _ defined using the _ keyword. getArea is an _ method and thus _

Static methods, static, instance, non static

for object p1 print string representation for the point

System.out.println(p1.toString());

The illustration of class templates and objects in Figure 9.2 can be standardized using Unified Modeling Language (UML) notation. This notation, as shown in Figure 9.4, is called a _ class diagram, or simply a _diagram.

UML, class

__ can be used to specify the visibility of a class and its members.

Visibility modifiers

It is a common mistake to put the _ in front of a constructor. But that makes it a method not a constructor.

Void keyword

The data field radius in the circle class is known as an __ which is tied to a specific instance of the class; it is not shared among objects of the same class. For example, suppose that you create the following objects: Circle circle1 = new Circle(); Circle circle2 = new Circle(5); The radius in circle1 is independent of the radius in circle2 and is stored in a different memory location.

instance variable (Changes made to circle1's radius do not affect circle2's radius, and vice versa.)

An object is an instance of a class. You can create many instances of a class. Creating an instance is referred to as _. The terms object and instance are often interchangeable.

instantiation

A visibility modifier specifies how data fields and methods in a class can be accessed from outside the class. There is no restriction on accessing data fields and methods from inside the class. An object can access its private members if it is defined in _.

its own class

The private modifier makes methods and data fields accessible only from within __

its own class

Java provides a system-independent encapsulation of date and time in the

java.util.Date class

You have used Math.random() to obtain a random double value between 0.0 and 1.0 (excluding 1.0). Another way to generate random numbers is to use the__, as shown in Figure 9.11, which can generate a random int, long, double, float, and boolean value.

java.util.Random class

To enable a private data field to be updated, provide a __ to set a new value. A getter method is also referred to as an accessor and a setter to a mutator.

setter method

The _ of an object (also known as its properties or attributes) is represented by data fields with their current values. A circle object, for example, has a data field radius, which is the property that characterizes a circle.

state

All the methods in the Math class are _. The main method is _, too

static

An instance method can invoke an instance or static method and access an instance or static data field. A static method can invoke a static method and access a static data field. However, a _ method cannot invoke an instance method or access an instance data field, since _ methods and data fields don't belong to a particular object

static

c1.numberOfObjects (line 27) and c2.numberOfObjects (line 30) are better replaced by CircleWithStaticMembers.numberOfObjects. This improves readability, because other programmers can easily recognize the _ variable.

static (Use ClassName.methodName(arguments) to invoke a static method and ClassName.staticVariable to access a static variable. This improves readability, because this makes the static method and data easy to spot.)

define static method numberOfObjects

static int getNumberObjects() {

/** Return numberOfObjects */ create method

static int getNumberOfObjects() { return numberOfObjects; }

static variable for /** The number of objects created */ syntax

static int numberOfObjects = 0;

declare static variable numberOfObjects

static int numberOfObjects;

If you want all the instances of a class to share data, use _ variables, also known as _ variables. Static variables store values for the variables in a common memory location. Because of this common location, if one object changes the value of a static variable, all objects of the same class are affected. Java

static, class

Note that static variables and methods are _ in the UML class diagram.

underlined

public class A { int i = 5; static int k = 2; public static void main(String[] args) { int j = i; // Wrong because i is an instance _ m1(); // Wrong because m1() is an instance __ } public void m1() { // Correct since instance and static variables and methods // can be used in an instance method ....

variable, method

Static variables and methods can be accessed _ creating objects.

without

True and false are _, null is a literal for a _.

Boolean literal, reference type

The object on which an instance method is invoked is called a _

Calling object

The following statement declares the variable myCircle to be of the Circle type

Circle myCircle;

Write s single statement to combine declaration of object reference variable, creation of object, & assigning of an object reference to the variable:

ClassName objectRefVar = new ClassName(); (Circle myCircle = new Circle();)

Declare reference variable syntax

ClassName objectRefVar;

A _ is invoked to crest an object using the _ operator

Constructor, new

A class may be defined without constructors. A public no-are constructor with an empty body is implicitly defined in the class. Called a _

Default constructor

An objects data and methods can be accessed through the _ operator via the objects _ variable

Dot, reference

Constructors play the role of _

Initialising objects

The method getArea is referred to as an _

Instance method (because it is dependent on a specific instance)

The data field radius is referred to as an _

Instance variable (because it is dependent on a specific instance)

_ variables belong to the instances and have memory storage independent of one another. _ variables are shared by all the instances of the same class.

Instance, static

The ___ contains a rich set of classes for developing Java programs

Java API

Null is a _ just like true or false

Literal

To construct an object from a class invoke a constructor of the class using the _

New operator

Constructor with no arguments

No-arg (or no argument constructor)

The data fields can be of reference types. If a data field of a reference type does not reference any object the data field holds a special Java value

Null

Object data can be accessed and its methods invoked using the dot operator also known as the __

Object member access operator

Objects of the same type are defined using a common class. A class is a template, blueprint, or _ that defines what an object's data fields and methods will be. An object is an _of a class.

contract, instance

A class is a template for _ objects

creating

A _ defines the properties and behaviors for objects.

class

When you compile TestCircleWithStaticMembers.java, the Java compiler automatically _ CircleWithStaticMembers.java if it has not been since the last change.

compiles

A Java class uses variables to define data fields and methods to define actions. Additionally, a class provides methods of a special type, known as _ , which are invoked to create a new object. They are designed to perform initializing actions, such as initializing the data fields of objects. Figure

constructors

Java API has a conveninent Point2D class in the _ package for representing a point in a two-dimensional plane

javafx.geometry

The behavior of an object (also known as its actions) is defined by _

methods

To declare a static variable or define a static method, put the _ in the variable or method declaration.

modifier static

Show constructor class creation syntax

new ClassName(arguments);

When you create a Random object, you have to specify a seed or use the default seed. A seed is a number used to initialize a random number generator. The _ constructor creates a Random object using the current elapsed time as its seed.

no-arg

/** Construct a circle with radius 1 & increase number of object by 1*/ CircleWithStaticMembers() { radius = 1; __

numberOfObjects++;

References a data field in the object. Syntax.

objectRefVar.dataField

Invokes a method on the object. Syntax.

objectRefVar.method(arguments)

The private modifier restricts access to its defining class, the default modifier restricts access to a _, and the public modifier enables unrestricted access.

package (If a class is not defined as public, it can be accessed only within the same package.)

Packages can be used to organize classes. To do so, you need to add the following line as the first noncomment and nonblank statement in the program:

package packageName;

You can use the public visibility modifier for classes, methods, and data fields to denote that they can be accessed from any other classes. If no visibility modifier is used, then by default the classes, methods, and data fields are accessible by any class in the same package. This is known as _ or _.

package-private, package-access

Every variable represents a memory location that holds a value. When you declare a variable, you are telling the compiler what type of value the variable can hold. For a variable of a _ type, the value is of the primitive type. For a variable of a _ type, the value is a reference to where an object is located.

primitive, reference

In most cases, the constructor should be public. However, if you want to prohibit the user from creating an instance of a class, use a private constructor. For example, there is no reason to create an instance from the Math class, because all of its data fields and methods are static. To prevent the user from creating objects from the Math class, the constructor in java.lang.Math is defined as follows:

private Math() {}

In addition to the public and default visibility modifiers, Java provides the _ and _modifiers for class members.

private, protected

The state of an object (also known as its _ or _) is represented by data fields with their current values

properties, attributes

A getter method has the following signature:

public returnType getPropertyName()


संबंधित स्टडी सेट्स

multiple choice ch.19,20,21,22,23,

View Set

Estate Planning: Forms of Property Ownership (Module 2)

View Set

Chapter 5: The American Revolution, 1776-1783

View Set

CH. 3 and 4 jurisdiction practice questions

View Set

Biology- Gene Expression and Inheritance

View Set