• Post Reply Bookmark Topic Watch Topic
  • New Topic

why do class include class?  RSS feed

 
de fa
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because the class define its objects' properties and operations, Class only include variables and methods.why do class include class?
[ November 18, 2005: Message edited by: de fa ]
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the question, can you clarify ?
 
de fa
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i mean why the class need the nested or inner class
[ November 18, 2005: Message edited by: de fa ]
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about hierarchy?
If so a class can have sub classes that are more precise version of the class. It is a convinience that safes alot of work.
For example you could make a class called Animal which has the Integer age the method eat().

Now you want to make another class called Horse that extends Animal i.e it inherits all it�s abilities i.e Horse has age, as do all animals and can eat like all other animals so you don�t have to include age or eat() in Horse. Now a horse can gallop so you could add a new method to Horse called gallop().
What we did here is we created a class with two methods(eat(),gallop()) and one variable(age) but with minimum effort.
Animal can have multiple subclasses f.ex Eagle which can�t gallop like the horse but can fly which the horse cannon. The horse and the Eagle are very unsimilar but they are both animals that�s why they would have the same superclass.

Hope this helps
[ November 18, 2005: Message edited by: Unnar Bj�rnsson ]
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me see if I can rephrase your question. I think you are asking the following:

A class normally contains properties and operations. What is the advantage of having a class also contain a nested or inner class?

Did I understand correctly?
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nested classes are used for various purposes, depending on who you talk to.
I use them to restrict scope, more closely align my software with my requirements, and improve encapsulation. While the language provides a somewhat "useful" mechanism in this respect, it is certainly not optimal.
 
de fa
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marilyn de Queiroz 'statement is my idea.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!