Java Objects Demonstration
Proof of understanding of objects
Objects
The code creates a public class called "Student", which takes in three different instance variables: class, teacher, and period. With these a string of "AP Computer Science A", another string of "Mr. Mortensen", and an integer of 2 are put together to print out the statement, "I have AP Computer Science A for Mr. Mortensen in period 2"
public class Student {
// instance variables
public String class;
public String teacher;
public int period;
public Student (String class, String teacher, int period) {
this.class = class;
this.teacher = teacher;
this.period = period;
}
public static void main(String[] args) {
Student s = new Student("AP Computer Science A", "Mr. Mortensen", 2);
system.out.println("I have " + s.teacher " for " + s.class + " in period " + s.period);
}
}
Hacks
Explain where a Class is defined
- A class is defined where you need variables, objects, or methods to be added to your code
Explain where an instances of a Class is defined
- An instance is defined in a Class as an object.
Explain where an object is Calling a Method
- An object can call a method when the action is needed to be used for the code to go through.
Explain where an object is Mutating data
- An object is mutation data when there is a change in the original data.
Describe Console, GUI differences, or Code.org differences.
- A console is where the user input and gets outputs.
-
Ex: Bash shell
-
A GUI is more clickable and user-friendly. There is also visual feedback and display.
-
Code.org used a painter as the visual object which shows the user what the code is doing. It has a public class as "MyNeighborhood". To call a method, you put "variableName.methodName();".