• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

A small doubt

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Marshal
Posts: 76887
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for clearing my doubt, but can you tell me how to pass the reference?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic