View Single Post
  #2 (permalink)  
Old 04-24-2007, 11:56 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,651
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

If you do like your first example you'll declare a class inside the other class. I don't think it's possible to do like you first example, in Java, because you use the extends-keyword before the class is even declared and/or implemented.

The other example is possible, because you declares another class outside any others, and use the extends-keyword after the first class is declared.

In your second example the class Vowel is inherited from the class Alfabet. That means the Vowel have the same functionality as Alfabet - but you have the option to extend Vowel with more.

I'm not a Java-programmer, but C++ isn't much different (syntax), so you'll probably could understand my example;
Code:
class Base
{
	public:
		void specialFunction()
		{
			std::cout << "This is a special function!" << std::endl;
		}
		
		void anotherSpecialFunction()
		{
			std::cout << "This is another special function!" << std::endl;
		}
};

// Java: class Derived extends Base
class Derived : public Base
{
	public:
		void aVerySpecialFunction()
		{
			std::cout << "This is a very special function!!!" << std::endl;
		}
};
If making an instance of class Base you'll only get access specialFunction and anotherSpecialFunction. If you then want to use an extended version of the class, then you can use Derived, which have another special function, aVerySpecialFunction, but this class can also access the ones from Base.
Code:
Base bInst;
Derived dInst;

// This is the only two functions we can access with an instance of Base
bInst.specialFunction();
bInst.anotherSpecialFunction();

// But with an instance of Derived, we can access the same ones + one more
dInst.specialFunction();
dInst.anotherSpecialFunction();
dInst.aVerySpecialFunction(); // Another function!
__________________
05-03-2007 - 11-13-2008
Reply With Quote