Peer Reviewers: @Patton-Burge, @ASoledadU
You are missing a lot of type information in your code samples. Remember, all methods must specify argument and return types.
|
```java |
|
class Richard { |
|
twoDaughter(); |
|
} |
|
class Aimee { |
|
twoDaughter(); |
|
} |
|
``` |
|
|
|
Once you find the similarities, you can break them up into a superclass: |
|
|
|
```java |
|
class Parents { // this is the superclass for the classes above it. |
|
twoDaughter(); |
|
} |
|
``` |
|
|
|
Once you create the superclass: |
|
|
|
```java |
|
class Aimee extends Parents { |
|
System.out.println("Hello"); |
|
} |
|
|
|
class Richard extends Parents { |
|
System.out.println("World"); |
|
} |
|
``` |
This code sample incorrectly suggests that you could just put statements like System.out.println(...);
or twoDaughter();
inside the class
definition.
A more appropriate sample might:
-
Define twoDaughter
on the Richard
and Aimee
classes.
-
Move twoDaughter
into the Parent
class.
-
Redefine Richard
and Aimee
to inherit from Parent
instead of defining twoDaughter
.
-
Demonstrate using twoDaughter
from a Richard
or Aimee
object.
-
@Patton-Burge verified fix
-
@ASoledadU verified fix
|
class Parent{ |
|
twoDaughter(); |
|
} |
|
|
|
class Aimee extends Parent { |
|
twoDaughter() { |
|
// this is where you tell the method what to override it with. |
|
} |
|
} |
The use statement calling twoDaughter
inside Parent
's definition is invalid. Parent
should provide an initial definition, not attempt to call it.
|
Object has an Instance Variable and methods, but these are design to work with the class. |
Objects can have multiple instance variables (gladiator.health
and gladiator.rage
).
|
```java |
|
class Dog { |
|
// instance variables |
|
int x; |
|
String breed; |
|
String name; |
|
|
|
void bark() { // a method |
|
System.out.println("RUFF! RUFF!"); |
|
} |
|
} |
|
``` |
|
### Writing a tester (TestDrive) class: second step |
|
|
|
``` java |
|
class DogTestDrive { |
|
public static void main(String[] args) {// main method |
|
// Dog test code goes here; |
|
} |
|
} |
|
``` |
|
In your tester, make an objects and access the object's variables and methods: third step |
|
|
|
``` java |
|
class DogTestDrive { |
|
public static void main(String[] args) { |
|
Dog d = new Dog(); //making this a dog object// |
|
d.size = 40; // to set the size of the Dog |
|
// use the dot operator (.) |
|
d.bark(); // ad to call its bark() method |
|
} |
|
} |
This section seems to have some formatting issues. Make sure that you are appropriately checking your output.
Neither of your sample applications demonstrate inheritance or overriding methods.