Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java multiple classes

Name: Anonymous 2012-01-25 12:13

http://www.youtube.com/watch?v=XqTg2buXS5o&feature=player_profilepage#t=179s

     tuna tunaObject = new tuna();



Someone care to explain why you need to type "tuna" at the beginning and "tuna()" at the end if you already stated that you're going to use the tuna class at the beggining?
I think I understand the "tunaObject" is(the variable to which you will assign the new class in the main class, right?), but the "new" is still kind of ... I don't understand it either...
:/

Name: Anonymous 2012-01-25 16:07

Tuna tuna = new Tuna();
Is more correct, class names usually begin with a uppercase letter.

Tuna is the "type" of the variable tuna in this case.

You could have:
Object tuna = new Tuna();

Since the Tuna class is also an Object. All classes implicitly extends Object.

You could have a superclass Fish for example,
and declare Tuna as:

public class Tuna extends Fish {
..
}

then you could treat all Tunas as Fishes.

Fish fish = new Tuna(); etc..

but then only the fish methods of tuna would be visible through that variable.

TLDR:
I suck at explaining things.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List