Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

A small doubt  RSS feed

 
Hari Mohanan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner in java. So I have a small doubt....compare these two classes:

Marks Analysis class



Marks Pages class




Now my doubt is, if I inherit MarkPages from MarkAnalysis, can I modify the values of the JFrame 'frame'? That is, the components in the previous class will not be used, instead I only give a new form to the existing JFrame 'frame'. According to my knowledge, 'frame' is an object of class JFrame. So can an object's state be inherited? (Sorry for using confusing sentences, i am a newbie)
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't understand the question; you have posted difficult code to read.

Moving to our GUIs forum.
 
Hari Mohanan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i am trying to say it, can i use the same JFrame (frame) as common for both the classes without defining a new one..
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hari Mohanan wrote:
Now my doubt is, if I inherit MarkPages from MarkAnalysis, can I modify the values of the JFrame 'frame'? That is, the components in the previous class will not be used, instead I only give a new form to the existing JFrame 'frame'. According to my knowledge, 'frame' is an object of class JFrame. So can an object's state be inherited? (Sorry for using confusing sentences, i am a newbie)


No, that is not what inheritance is for, for one, and for two, it simply won't work. Whenever you consider having one class extend another you must ask yourself is the child class a more specialized version of the parent class, for instance, a Dog a more specialized instance of an Animal, but Bark is not a more specialized version of Dog. The next issue is, even if it's not right, will it work? and the answer is no, it will not, since each class will own its own separate JFrame instance that are completely unrelated to each other.

The solution is to pass a reference of one class to the other.
 
Hari Mohanan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for clearing my doubt, but can you tell me how to pass the reference?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> but can you tell me how to pass the reference?

really, that's on about page 1 of any beginner's book.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!