Lecture 8.2 - Multi-Dimensional Arrays
Lecture 8.2 - Multi-Dimensional Arrays
// this will become its own file too (and these can be in any order)
public class OtherClass {
public String message;
public OtherClass(String input) {
message = input;
}
} © Copyright 1992-2012 by Pearson
Education, Inc. All Rights Reserved.
// our main class becomes a file but the main method is still found
public class HelloWorld {
public static void main(String[] args) {
OtherClass myObject = new OtherClass("Hello World!"); Output:
System.out.println(myObject.message);
passObject(myObject);
Hello World!
System.out.println(myObject.message);
}
Hello World!
public static void passObject(OtherClass c2) {
c2 = new OtherClass(“A changed message”):
}
}
// this will become its own file too (and these can be in any order)
public class OtherClass {
public String message;
public OtherClass(String input) {
message = input;
}
}
items.add("blue");
items.remove("red");
display(items); OUTPUT
new
blue
alIntegers.add(23); // no error
alIntegers.add(new Integer(25));
Integer myInt = new Integer(100);
alIntegers.add(myInt);
reference types.
Next example uses an array of reference-type elements
the face of the card, " of " and the suit of the
card.
Can invoke explicitly to obtain a string representation of a
Card.
Called implicitly when the object is used where a String is
expected.