![]() |
![]() |
|
Code developed: Song.java
I will give examples of objects using
new Footakes in a String and returns a Foo. (update picture)
class Song {
String title;
String artist;
double length; // in seconds.
boolean isCopyrighted;
}
|
class Robot {
String id;
String shape;
boolean isTransformed;
boolean isEvil;
}
|
Constructors are just functions:
You pass them arguments, and they return a value — in particular,
they return a newly-constructed object (a
Java forces you to write constructors a bit differently than most functions, though:
— that's implicit by the fact that it's a constructor.static
class Song extends Object120 {
String title;
String artist;
double length; // in seconds.
boolean isCopyrighted;
// define the constructor:
Song( String t, String a, double l, boolean c ) {
//some voodoo (for now):
super(t,a,l,c);
}
static void testSongs() {
Song s;
s = new Song( "Help!", "The Beatles", 122, true );
}
}
|
to teacher: Reached this far Oct.04.
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland |