How do you call a method?
When we call a method, we specify the object followed by the dot operator then the name of the method we want to use.
I display the attributes and behaviors within a class.
What is the format for creating a new object.
class name object name = new object name
This capitalization structure is used when naming anything in Java. It consists of the first letter of first word being uppercase or lowercase, and the first letter of any additional word is upper case.
camel casing
What is the following code segment an example of?
public void move() {
// code to make a Painter object move
}
Void Method
I contain the following:
-The same name as the class
-Fields
-Methods
Constructor
I am used to construct a new object
new keyword
contain "class" keyword and the name of the class
ex. class Basketball {
}
class header
A value we pass to a method when we call it. The values in () when we create an object using the "new" keyword are?
Parameters
We are the characteristics of the class and the tasks an object can perform.
Attributes and behaviors
What is meant by the "state" of an object and how is it determined?
The current values of the parameters
What is the following an example of:
public static void main (string [] args)
Main Method
How would you overwrite a method in a subclass?
Provide an example
class Parent {
void show()
{
System.out.println("Parent's show()");
}
}
// Inherited class
class Child extends Parent {
// This method overrides show() of Parent
@Override
void show()
{
System.out.println("Child's show()");
}
}
A student has created a Cat class. The class contains variables to represent the following.
The object tabby will be declared as type Cat.
Which of the items listed above are an attribute of Cat?
coatPattern, age
/* data type 1 */ x = 0.5;
/* data type 2 */ y = true;
Which of the data types should be used to replace/* data type 1 */ and /* data type 2 */ so that the code segment compiles without error?
The variable x should be declared as a double and the variable y should be declared as a boolean.
Consider the following code segment.
int j = 10;
int k = 8;
j += 2;
k += j;
System.out.print(j);
System.out.print(" ");
System.out.println(k);
What is printed when the code segment is executed?
12 20
From what you remember about the painter class create a method that will allow the painter to do a full circle turn with an ending position facing right.
*Assume the painter's starting position is facing left.
public void faceRight() {
turnLeft();
turnLeft();
turnLeft();
turnLeft();
turnLeft();
turnLeft();
}
What is the relatisonship between a super class and a subclass? What is the one component of the superclass that is not inherited from the super class?
Provide an example of an extended subclass
subclass: a class that extends a superclass and inherits its attributes and behaviors
superclass: a class that can be extended to create subclasses
ex.public class PainterPlus extends Painter
Objects 500
A teacher determines student percentages in a course as the points a student earns divided by the total points available in the grading period. Points are awarded only in whole number increments, but student percentages are to be stored as decimals.
The following code segment appears in a program used to compute student percentages. Points that a student earns are stored in pointsEarned, the total points available in the grading period are stored in totalPoints, and the student percentage is stored in percentage.
int pointsEarned;
/* missing code */
int totalPoints;double percentage;
Consider the following code segment.
int x;
int y;
x = 3;
y = /* missing expression */;
x = 1 + 2 * y;
System.out.print(x);
System.out.println(y);
Which of the following can be used as a replacement for /* missing expression */ so that the code segment prints 94 ?
x + 1