Study your flashcards anywhere!

Download the official Cram app for free >

  • Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key


Play button


Play button




Click to flip

14 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
What is the basic syntax for declaring a class?
class MyClass {
//field, constructor, and method declarations
You can also add modifiers like public or private at the very beginning. You can use extends or impliments as well to extend a superclass or impliment an interface.
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 their values?
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, {}.
More generally, method declarations have six components, in order:

1. Modifiers—such as public, private.

2. The return type—the data type of the value returned by the method, or void if the method does not return a value.

3. The method name

4. The parameter list — a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.

5. An exception list

6. The method body, enclosed between braces—the method's code, including the declaration of local variables, goes here.
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 draw(int i) {

What is this called?
overloading methods
Note: these methods should be used sparingly, as they can make code much less readable.
The declaration for a method or a constructor declares the ______ and the ______ of the arguments for that method or constructor.
number and type
Note : Parameters refers to the list of variables in a method declaration. Arguments are the actual values that are passed in when the method is invoked. When you invoke a method, the arguments used must match the declaration's parameters in type and order.
What kinds of parameters can be used in a method?
Any data type
Note : The Java programming language doesn't let you pass methods into methods. But you can pass an object into a method and then invoke the object's methods.
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 parameter, including none. Ex:

public Polygon polygonFrom(Point... corners)
A "variable number of arguments"
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
Any changes to the values of these parameters exist only within the scope of the method.
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.
Note: The values of the object's fields can be changed in the method, if they have the proper access level.
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.
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.