> try to OK Now. Thank a lot. What problem ?
>
[quoted text clipped - 13 lines]
> }
> }
These are all the changes? Did you change anything else?
> D:\Example\javaux\OO>java appmotor
>
[quoted text clipped - 11 lines]
> Speed is 100 mph
> D:\Example\javaux\OO>
Using your source from original post: Its main method call showDetail()
once. The above output has more lines. The first problem looks
resolved. Repost source code.
opalpa
opalpa@gmail.com
http://opalpa.info/
moonhk - 11 Oct 2006 05:45 GMT
Source Code as below
I add some coding
such as in
public void showDetails() {
// calls the superclass by prefixing it with a super
super.showDetails();
// Add New Item
System.out.print("\tSpeed is " + speed + " mph");
}
Also, do you how to call Motorcycle.showDetails() ?
Motorcycle.java
============
import java.util.*;
import java.text.*;
class Motorcycle {
private String Model;
private String Color;
private int Year;
private Date EngineStartDate;
private boolean engineStatus = false;
void setModel (String loName) {
this.Model = loName;
}
void setColor(String loColor) {
this.Color = loColor ;
}
void setYear (int loYear) {
this.Year = loYear;
}
public void showDetails() {
System.out.println("\nDetails:");
System.out.println("\tModel is " + this.Model);
System.out.println("\tColor is " + this.Color);
System.out.println("\tYear is " + this.Year);
System.out.println("\tEngine Started on " + EngineStartDate );
}
public void startEngine() {
if (engineStatus == true)
System.out.println("\nThe engine is alreay on. " + EngineStartDate
+ " (" + this.Model + ")");
else {
engineStatus = true;
EngineStartDate = new Date();
System.out.println("\nThe engine is now on. " + EngineStartDate +
" (" + this.Model+ ")");
}
}
}
/* eof */
appmotor.java
==========
import java.lang.*;
/* Testing Inheritance */
class M2 extends Motorcycle {
private int speed;
public void setSpeed(int loSpeed) {
this.speed = loSpeed ;
}
public int getSpeed() {
return this.speed;
}
public void showDetails() {
// calls the superclass by prefixing it with a super
super.showDetails();
// Add New Item
System.out.print("\tSpeed is " + speed + " mph");
}
}
/* Main Part */
public class appmotor extends Thread {
public static void main (String args[]) {
M2 m = new M2();
m.setModel ("Yamaha RZ350");
m.setColor ("Yello");
m.setYear (2003);
m.setSpeed(100);
m.startEngine();
m.showDetails();
try {
sleep (4000);
} catch ( InterruptedException e) {}
m.startEngine();
m.showDetails();
}
}