Jump to content

Error: oldTelevision is already defined in unamed package

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Devilb0y

Devilb0y

    Newbie

  • Members
  • PipPip
  • 10 posts
So first off, I am aware how basic this is. I've been programming for two days so to call myself a newbie would be an understatement. With that in mind:

I was following a tutorial on the Java website about object oriented programming, particularly classes and interfaces.

I had defined a class (oldTelevision) and then defined an interface (Television). I then used 'class oldTelevision implements Television' to try and tell oldTelevision how to act but was faced with the error message : "oldTelevision is already defined in unamed package".

Now, I get why it's saying this. I've already defined the states and behaviours of the oldTelevision class so my programme is confused as to why I'm trying to define these things again with an interface. But because of this I'm not really sure what the point of an interface is if I can write an objects behaviour right into it's class. The only exception I can think of would be if you were using the interface to define the behaviour of subclasses.

This has confused me though, because as far as I can see you have to define a class before you can tell it to implement anything, but by defining it you're removing the need for an interface.

I'll include my script below for people to check out but I hope you guys can help as this feels a bit like a brick wall.

Thanks in advance,

Dev.


class oldTelevision {

            

    int On = 0;

    int Off = 0;

    int Volume = 0;

    int Brightness = 0;        

    

    void turnOn (int newValue) {

        On = newValue;

        Off = newValue - newValue;

    }

    void turnOff (int newValue) {

        Off = newValue;

        On = newValue - newValue;

    }

    void upVol (int increment) {

        Volume = Volume + increment;

    }

    void downVol (int decrement) {

        Volume = Volume - decrement;

    }

    void upBright (int increment) {

        Brightness = Brightness + increment;

    }

    void downBright (int decrement) {

        Brightness = Brightness - decrement;

    }


interface Television {

    

    // image on screen

    

void turnOn (int newValue);


void turnOff (int newValue);


void upVol (int increment);


void downVol (int decrement);


void upBright (int increment);


void downBright (int decrement);

    

}


class oldTelevision implements Television {


}



#2
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
This error was explained here: http://forum.codecal...html#post322526
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/

#3
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
You are declaring class OldTelevision twice.
once in the beginning of the code and once in the end.
remove the second declaration and alter the first one to implement "Television"
.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users