Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Code Error  (Read 2265 times)
0 Members and 1 Guest are viewing this topic.
Space Xscape
Guest
« Posted 2007-07-29 00:47:10 »

The following code gives me this error when i try to compile it alone:

Quote
--------------------Configuration: Space Xscape - JDK version 1.6.0_02 <Default> - <Default>--------------------
C:\Projects\Java\SpaceXscape\GameObject.java:1: GameObject is not abstract and does not override abstract method Update() in GameObject
public class GameObject {
       ^
1 error

Process completed.

Here is the code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class GameObject {

    private int x;
    private int y;
    private float x_velocity;
    private float y_velocity;

    public abstract void Draw();

    public abstract void Update();
   
}


Any ideas?
Offline 2playgames

Junior Member





« Reply #1 - Posted 2007-07-29 01:19:10 »

i don't think a non-abstract class can have abstract methods, because then you could create instances of it which don't have that method implemented.

so add a (empty) implementation to those methods, or make the whole class abstract

Offline keldon85

Senior Member


Medals: 1



« Reply #2 - Posted 2007-07-29 01:38:48 »

Yes, only abstract classes can have abstract methods. Note that the private data will not be accessible to derived classes, so if you do want them to be accessible then make them protected.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ravenger

Senior Newbie





« Reply #3 - Posted 2007-07-30 12:24:33 »

to add; technically a class with abstract methods is an abstract class Wink and you cant instantiate something that doesnt know how to behave Smiley
Offline Mr_Light

Senior Member




shiny.


« Reply #4 - Posted 2007-07-30 13:54:48 »

An abstract class doesn't need abstract methods at all, to be abstract.
1  
2  
public [b]abstract[/b] class Foo {
}

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline keldon85

Senior Member


Medals: 1



« Reply #5 - Posted 2007-07-30 14:37:31 »

An abstract class doesn't need abstract methods at all, to be abstract.
1  
2  
public [b]abstract[/b] class Foo {
}

Well that would be completely pointless Cheesy

Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #6 - Posted 2007-07-30 15:33:32 »

Well that would be completely pointless Cheesy

Sun obviously don't agree... java.awt.Component

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline keldon85

Senior Member


Medals: 1



« Reply #7 - Posted 2007-07-30 16:09:10 »

Sun obviously don't agree... java.awt.Component
I'm talking about an empty abstract class! A class with abstract methods is an abstract class, that statement doesn't mean that a class without abstract methods is not an abstract class Smiley

Offline Kova

Senior Member





« Reply #8 - Posted 2007-07-31 02:51:09 »

I'm talking about an empty abstract class! A class with abstract methods is an abstract class, that statement doesn't mean that a class without abstract methods is not an abstract class Smiley

that code was just an example of abstract class with no abstract methods, nothing to do with empty abstract classes (although it is one), your reply seems to be on sentence so this where confusion started Wink
Offline keldon85

Senior Member


Medals: 1



« Reply #9 - Posted 2007-07-31 10:56:52 »

that code was just an example of abstract class with no abstract methods, nothing to do with empty abstract classes (although it is one), your reply seems to be on sentence so this where confusion started Wink
Well I'm not confused in any way; Mr Light took the statement of abstract methods implies abstract class to mean abstract class implies abstract methods Smiley Of course I was just saying that an empty class is pointless, then Abuse thought I was talking about an abstract class with no abstract methods Cheesy

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #10 - Posted 2007-07-31 12:33:53 »

Though empty interface/classes are quite common for tagging purposes: Serializable. Could argue this has been superceeded by annotations though.

Kev

Offline keldon85

Senior Member


Medals: 1



« Reply #11 - Posted 2007-07-31 13:24:47 »

Though empty interface/classes are quite common for tagging purposes: Serializable. Could argue this has been superceeded by annotations though.

Kev
IMO that's the exception of the rule as what they wanted to create was a class/interface that made your class serializable however they couldn't make it a class as it would restrict derived classes from extending anything else and did not want to create an interface with a method that you only implement if you want a custom implementation.

What they could have done is either (a) had a method that stated whether it had a custom implementation with a corresponding empty method, or (b) had the methods return a boolean stating whether or not it wanted it to be processed in the default way. But having said that it does make sense to create an empty interface if your class agrees to a particular pattern that cannot (or should not) force a specific implementation. An example would be having all methods beginning with verify* to have a corresponding process* for every create* (or something of that nature).

Offline Mr_Light

Senior Member




shiny.


« Reply #12 - Posted 2007-08-01 17:33:49 »

What I was saying is that abstract methods don't make the class abstract at all. Methods are 2nd to the class definition. A class with abstract methods isn't an abstract class at all. Your turning abstract classes only permit abstract methods around, just because the compiler throws an error if that contact is not held. Because of the contact abstract methods do imply an abstract class. However if you blindly decorate a class with abstract every time you define an abstract method your doing something wrong. Yeah next thing you know you have IFoo AbstractFoo Foo or other stupid nonsense all over the place.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline purpleguitar

Junior Member





« Reply #13 - Posted 2007-08-02 15:31:49 »

A class with abstract methods isn't an abstract class at all. Your turning abstract classes only permit abstract methods around,

It is not the case that abstract classes only permit abstract methods; if that were the case, then they would be interfaces.  Abstract methods may only be defined within abstract classes.  See http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html, or try to compile:
1  
class AbsTest { abstract void foo(); }


Incidentally, one may define methods within an interface as abstract, although it is redundant.  One may also define interfaces as abstract, but it has no meaningful semantics.  I have done this as an note to myself that I intend to create a subinterface of the abstract interface.
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2007-08-02 16:39:00 »

Quote
IMO that's the exception of the rule as what they wanted to create was a class/interface that made your class serializable however they couldn't make it a class as it would restrict derived classes from extending anything else and did not want to create an interface with a method that you only implement if you want a custom implementation.

It's true Serialization is a special case. However, as you say later using an empty interface (or class in some cases) makes sense when you're defining something that conforms to some entity description but doesn't require any additional method implementations, so I'd hardly consider Serialization the only exception to the rule that empty interfaces/classes are useless. Useless to a coder, useful to a designer maybe Wink. It's often referred to as a tagging (or marker) interface.

Kev

Offline Mr_Light

Senior Member




shiny.


« Reply #15 - Posted 2007-08-03 03:48:00 »

It is not the case that abstract classes only permit abstract methods; if that were the case, then they would be interfaces.  Abstract methods may only be defined within abstract classes.  See http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html, or try to compile:
you misinterpreted, perhaps the order in the sentence is wrong, I didn't mean/say? abstract classes permit abstract and only abstract methods. "It is only in abstract classes that abstract methods are permitted."

Interfaces are abstract classes with a special contract that specifies that no concrete methods are allowed. Because of java's inheritance system/strategy/philosophy there are special abstract classes. (Interfaces don't exist in general OO the word was lend from system-design)

I believe the JLS is a bit more foggy/fuzzy about it, but I count interfaces as abstract classes, so yes as we both said; Abstract methods may only be defined within abstract classes.

But the point I was making was... etc.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (57 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!