Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: please explain me these java class :)

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
    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,

    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


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,332
    My Mood
    Hungover
    Thanks
    143
    Thanked 624 Times in 535 Posts

    Default Re: please explain me these java class :)

    What exactly is your question?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: please explain me these java class :)

    Quote Originally Posted by me. View Post
    ... explain...getting errors
    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
    Last edited by Zaphod_b; October 18th, 2012 at 01:22 PM.

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM
  2. i need an explain please !
    By keep smiling in forum Java Theory & Questions
    Replies: 3
    Last Post: December 21st, 2011, 10:22 AM
  3. Don't know java ...Need help compare, explain 2 different versiosn of code.
    By asian2003k in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 9th, 2011, 12:41 PM
  4. New to Java, could you explain something to me?
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 6
    Last Post: September 18th, 2011, 07:12 AM
  5. Replies: 1
    Last Post: December 13th, 2010, 04:13 AM