please explain me these java class :)
hi there :)
my first threat and first java code so these moght be dumb question for you but I will appreciate if you explain these to me.
having code and working in eclipse getting errors
Code :
he public type cat must be defined in its own file
The public type giraffe must be defined in its own file
:
here is the code,
Code :
public class ananimal {
public void animalnoise(){
System.out.println("All animals noise is eating");
}
public void walking(){
System.out.println("one foot in front of the other");
}
public static void main (String[] args){
giraffe john = new giraffe();
john.animalnoise();
john.eatswhat();
john.walking();
cat timmy = new cat();
timmy.animalnoise();
timmy.eatswhat();
timmy.walking();
ananimal allanimals = new ananimal();
allanimals.animalnoise();
}
}
public class cat extends ananimal {
public void animalnoise(){
System.out.println("Miaow, Miaow");
}
public void eatswhat(){
System.out.println("Kite Kat");
}
}
public class giraffe extends ananimal {
public void animalnoise(){
System.out.println("Giraffe noise, giraffe noise");
}
public void eatswhat(){
System.out.println("Leaves on trees");
}
}
THANK YOU
Re: please explain me these java class :)
What exactly is your question?
Re: please explain me these java class :)
Quote:
Originally Posted by
me.
... explain...getting errors
Code :
he public type cat must be defined in its own file
The public type giraffe must be defined in its own file
It is telling you that each of your public classes must be in a separate file.
Specifically, Java requires:
Your public class ananimal must be in a file called ananimal.java
Your public class cat must be in a file called cat.java
Your public class giraffe must be in a file called giraffe.java
Cheers!
Z
Re: please explain me these java class :)
Java file should have one and only public class..
public class name should be the name of your java file.
Re: please explain me these java class :)
hi and thanks for answer,
I'm completely new to java and I sat down to write first code before even reading about java which was completely confusing
first used bluefish and believe class animal must be in a file called animal.java
but now I try to write it on eclipse and making new class makes new file I guess, any way classes works now!
thanks for pointing that out.