This site is 100% ad supported. Please add an exception to adblock for this site.

Java Classes and Objects

Terms

undefined, object
copy deck
What is the basic syntax for declaring a class?
class MyClass {
//field, constructor, and method declarations
}
What are 3 types of class variables?
Member variables in a class—these are called fields.

Variables in a method or block of code—these are called local variables.

Variables in method declarations—these are called parameters.
What is the difference between the public modifier and the private modifier?
public modifier—the field is accessible from all classes.

private modifier—the field is accessible only within its own class.
In the spirit of encapsulation, it is common to make fields private. This means that they can only be directly accessed from within their class. We still need access to these values, however. How can we keep these variables private, yet still access thei
This can be done indirectly by adding public methods that obtain the field values for us.
What are the (only) required elements of a method declaration?
return type, name, a pair of parentheses, (), and a body between braces, {}.
Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists. ex:

public void draw(String s) {
...
}
public void dr
overloading methods
The declaration for a method or a constructor declares the ______ and the ______ of the arguments for that method or constructor.
number and type
What kinds of parameters can be used in a method?
Any data type
What construct is used to pass an arbitrary number of values to a method? The sytax of which is the type of the last parameter by an ellipsis (three dots, ...), then a space, and the parameter name. The method can then be called with any number of that p
varargs
Primitive arguments, such as an int or a double, are passed into methods by value. When the method returns, what happens to the changes to these values?
They are lost
Reference data type parameters, such as objects, are passed into methods by value. When the method returns, the passed-in parameter(s) reference what?
The same object as before.
A typical Java program creates many ________, which interact by invoking methods. Through these, a program can carry out various tasks, such as implementing a GUI, running an animation, or sending and receiving information over a network.
objects
What does this code do?

Tree tree1 = new Tree();
Creates a new Tree object named tree1.
What is the easiest way to identify a constructor?
A constructor uses the same name as its class and has no return type.

Deck Info

14

permalink