multiple inheritence

  • Thread starter shruti via JavaKB.com
  • Start date
S

shruti via JavaKB.com

how do i implement multiple inheritence using interfaces.actually i need to
access value of a combobox of a class from some other class where both the
classes extend jframe
 
J

Joona I Palaste

shruti via JavaKB.com said:
how do i implement multiple inheritence using interfaces.actually i need to
access value of a combobox of a class from some other class where both the
classes extend jframe

What's wrong with the answer Rajesh Rapaka posted 23 minutes after your
original question?
 
T

Thomas G. Marshall

Joona I Palaste coughed up:
What's wrong with the answer Rajesh Rapaka posted 23 minutes after
your original question?


Because it doesn't explain how to get to a variable of an /existing/ class
without recreating it.
 
S

shruti tiwari via JavaKB.com

nah rajesh was rite n it worked allrite...jst gave me a few problems in the
beginning when i didnt use the keyword static ...static it seems is
mandatory to use n if i follow the exact procedure given by rajesh it will
giv the required results allrite....
 
T

Thomas G. Marshall

shruti tiwari via JavaKB.com coughed up:
nah rajesh was rite n it worked allrite...jst gave me a few problems
in the beginning when i didnt use the keyword static ...static it
seems is mandatory to use n if i follow the exact procedure given by
rajesh it will giv the required results allrite....

I'm sorry, but would you be up for posting your code here? I'm worried that
you may have stumbled right into bad design. Rajesh would not be at fault
here either, he was speaking specifically to the language facility. But
your solution of directly accessing a variable elsewhere is a common Bad
Idea (tm)----not always, but almost always.
 
P

P.Hill

Thomas said:
shruti tiwari via JavaKB.com coughed up:
But
your solution of directly accessing a variable elsewhere is a common Bad
Idea (tm)----not always, but almost always.

But then so is writing messages in telegram like English shorthand
misspellings popular with people who IM over cellphones and other small
devices.

To the OP, please communicate in full standard English words.

-Paul
 
T

Thomas G. Marshall

P.Hill coughed up:
But then so is writing messages in telegram like English shorthand
misspellings popular with people who IM over cellphones and other
small devices.

To the OP, please communicate in full standard English words.

Agreed. Right or wrong, I saw the post and thought to myself: 17 years old.
 
A

Andrew McDonagh

Thomas said:
P.Hill coughed up:



Agreed. Right or wrong, I saw the post and thought to myself: 17 years old.

I think you give too much credit...I was thinking either 15 or lazy.
 
S

shruti tiwari via JavaKB.com

This is my code and it works just fine....

in the first class:
public class home extends javax.swing.JFrame implements ActionListener{

public static String temp5;
}
second class:
public class child extends javax.swing.JFrame implements ActionListener{
home coobj=new home();
public child(){
System.out.println(coobj.temp5);
}
 
T

Thomas G. Marshall

shruti tiwari via JavaKB.com coughed up:
This is my code and it works just fine....

in the first class:
public class home extends javax.swing.JFrame implements
ActionListener{

public static String temp5;
}
second class:
public class child extends javax.swing.JFrame implements
ActionListener{ home coobj=new home();
public child(){
System.out.println(coobj.temp5);
}

I'm sorry, I'm more than a little furious. I had over a page of
reformatting and explanations, and then my newsreader crashed. Let me cool
off before elaborating again.

In summary, here's the gist:

1. Always capitalize your class names or you'll confuse
the bejeebers out of other java guys reading your code.
Why this wasn't a fiat established by the language
spec, I'll never know.

2. 4 spaces for indents please. There are some that
argue with this, but most folks agree with 4 spaces.
Chances are great, however, that your indents got
screwed up simply by cutting and pasting into some
newsreaders.

3. In your example, you're creating a new Home object
every time the action listener is called. Given that,
you should have complete access to anything public
within it, /without/ the static:

public class Home (etc.) {
public String temp5;
}

elsewhere:
Home home = new Home();
System.out.println(home.temp5);

If you really wanted temp5 to be a static, then all you
needed to write was:

System.out.println(Home.temp5); // <-class name

4. If your code snippet is to grow in complexity, keep
in mind that there are likely to be multiple threads
accessing your object. There are too many ways
for this thing to grow, so I cannot comment on them
all, but keep in mind that you might just want to have
something of this form:

public class Home (etc.) {
private String temp5;
public String get() {
return temp5;
}
}

a. This keeps the temp5 from being settable by
others.
b. This gives you greater control later on as to when
specifically the string is retrieved. Something else
might be in the middles of constructing that string
when a method someplace tries to access it. Again,
just keep this in mind.

5. You never set your string to anything before using
it. I'll assume that you are doing so elsewhere.
 
J

Joona I Palaste

Thomas G. Marshall said:
shruti tiwari via JavaKB.com coughed up:
I'm sorry, but would you be up for posting your code here? I'm worried that
you may have stumbled right into bad design. Rajesh would not be at fault
here either, he was speaking specifically to the language facility. But
your solution of directly accessing a variable elsewhere is a common Bad
Idea (tm)----not always, but almost always.

You mean you could actually read that?

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The large yellow ships hung in the sky in exactly the same way that bricks
don't."
- Douglas Adams
 
T

Thomas G. Marshall

Joona I Palaste coughed up:
Thomas G. Marshall



You mean you could actually read that?

If you blur your eyes a lot, you can sort of guess at the general "shapes"
of the words...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top