Java Abstract Classes


 
Thread Tools Search this Thread
Top Forums Programming Java Abstract Classes
# 1  
Old 11-16-2014
Java Abstract Classes

Can anyone tell me if this is correct when creating classes in Java?

Code:
public abstract class Animal
{
   public class Point
   {
      public int x,y;
   }  
   public class Animal
   {
      protected Point loc;
      protected String name;
      protected Random rng;
      String getName()
      {return name;}
 
      Point getLocation()
      {return loc;}
 
      void setStartLocation(Point p)
      {
      }  
      Animal( String name, Random rng )
      {
         this.name = name;
         this.rng;
      }  

      void move()
      {
      }  
   }

 public class Cat extends Animal
     {
      }


Do I put anything under void setStartLocation and void move? This is for a game where a cat is chasing a mouse on a island(grid).

Another thing I am not sure of is how would I override the move method to randomly move north, south, east or west under the Cat class. Would it be something like move.random()?

Thank you for any help.
# 2  
Old 11-28-2014
It looks like your {} are not balanced, and you need functonality, but all Animals can inherit move() unless their movements are variably restricted.
# 3  
Old 11-28-2014
No, it's not strictly correct. Your move() method is not abstract - it exists even though it does nothing. Abstract classes (usually) have unimplemented methods:

https://docs.oracle.com/javase/tutor.../abstract.html
# 4  
Old 12-02-2014
Abstract is where you put common members and interfaces, and for methods that are likely to be shared, the actual method. If the actual method is not provided, the child object must define it.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Set java classes path

I add some new java jar files in the old project, how can I edit the class path? How can I compile all the java classes by just type 'C':o (3 Replies)
Discussion started by: Hscript
3 Replies

2. Programming

C++ abstract (singleton) factory implementation...

I want to create an abstract factory template which will allow me to pass in an "ID" for a subclass and return the singleton instance of that class stored in the factory. It'd be easy to adapt for "multi-ton", but for its present use this isn't necessary. The requirements are: - I don't want... (2 Replies)
Discussion started by: DreamWarrior
2 Replies

3. Shell Programming and Scripting

abstract.sh

A highly abstract function invocation, just enjoy it ,guys! #!/bin/bash loop() { for((${1}=0; ${1}<${2}; ++${1})); do eval \$\{{3..12}\} done } numb() { echo -n "${!1}${!2}${!3} " (( ${3} == 2 )) && echo } eval loop" "{i..k}" 3" numb {i..k} (10 Replies)
Discussion started by: complex.invoke
10 Replies

4. Programming

how abstract class differs in Java and C++?

hello all, i want to know if there is any difference in working and syntax declaration of abstract class in Java and C++. (1 Reply)
Discussion started by: haravivar
1 Replies

5. Programming

Use of C++ Classes

I was wondering if I could put the section at the beginning rather than at the end before the definition of the class. const REAL ModMisfit::DefMinDT = 0.01; const REAL ModMisfit::DefSigma0 = 0.01; const double ModMisfit::DefDAngSh = 2; const REAL ModMisfit::DefKBeta = 5;... (2 Replies)
Discussion started by: kristinu
2 Replies

6. Programming

how can compile cpp code containing references to java classes

hi there is example (on link given below )of such code that contains java class reference in c++ program. http://slackware.cs.utah.edu/pub/slackware/slackware-7.1/docs/Linux-HOWTO/Process-Monitor-HOWTO I am new in linux environment. and not able to compile it. when i compile it through... (1 Reply)
Discussion started by: surinder
1 Replies

7. Programming

how to use classes in c ?!?!?

Hi, I've tried to use classes in my program, but the compiler simply gives an error on the word class . Am I the only one with this problem ? I have no idea how to use classes in c in linux environment(suse). If you've got any idea what should I do I would be very thankful. Thanks to ya all !... (4 Replies)
Discussion started by: atticus
4 Replies

8. Shell Programming and Scripting

How to call Java classes/methods from ksh

Hi all, i am new to shell scripts and have one doubt. Can we call ava classes/methods from shell scripts? if yes how? (17 Replies)
Discussion started by: girish.sh
17 Replies
Login or Register to Ask a Question