|
||||||
| Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I know what data is, I mean outside of programming languages, but I read that data and methods make classes. I now know what methods are, but what is "data". Is it just everything else, like the syntax and such?
|
| Sponsored Links |
|
|
|
|||||
|
the "data" would be the variables within the class. It could be ints, floats, or even other classes.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||||
|
A subclass usually refers to a class that has been derived from another class. For example, the class of dogs is a subclass of the class of animals. (This terminology might come from set theory). A class within a class might be called a member class.
As far as can it be done, yes. Consider your car: it has an engine, wheels, etc. So if you are modeling it with classes, you would have an engine class, a wheel class, and a car class that has an engine and an array of wheels as members. The engine would have information such as the number of cylinders. The wheels would have information such as size and if they're flat or spare. The car would include the manufacturer.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||||
|
I'm a little rusty on Java, so my example will be in C++.
Code:
class piece
{
public:
bool moveTo(x,y);
bool isThreatend();
TYPE pieceType();
private:
COLOR color;
}
class pawn : piece
{
private:
bool EnPassante;
}
pawn myPawn;
piece myPiece;
myPawn has two data value: myPawn.color (inherited from the piece class) and myPawn.EnPassante COLOR is an enumeration for the colors of chess pieces (Black and White). Now I can make another class: Code:
class Board
{
public:
void PlayGame();
private:
piece pieces[16][2];
}
Now, with a few more classes and some code for the methods, you have a chess program ![]()
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Issue writing to file: pointer to a class which contains pointers to other classes | Sheemer | C and C++ | 0 | 08-21-2007 01:17 AM |
| Multiple classes in one namespace | NeedHelp | Managed C++ | 2 | 06-29-2006 03:35 PM |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| gaylo565 | ........ | 18.00000 |
| WingedPanther | ........ | 15.00000 |
| |pH| | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 65%