BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-21-2009, 06:35 PM   #1
doni49
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Default Properties/Methods of Parent Class not available to Child Class?

Please Login to Remove!

Given the following code, why is "NextKey" not available to methods in MyClass2?

I always thought that when you extend a class, all of the member methods and properties would be part of the second class--otherwise, what's the point of extending an existing class?

Code:
class MyClass1{
  public int getNextKey(){
    return _NextKey;
  }
  public void setNextKey(int val){
    _NextKey = val;
  }
  MyClass1(){
  }
  private int _NextKey;
}

class MyClass2 extends MyClass1{
  MyClass2(){
    super();
  }
  public void doSomething(value){
    _NextKey = value;
  }
}
__________________
Don

Handspring Visor -> Handspring Visor Deluxe -> Palm Treo 650 on VZW -> Palm Treo 700p on VZW -> Blackberry Tour 9360 on VZW

Last edited by doni49; 10-21-2009 at 06:46 PM..
Offline  
Old 10-22-2009, 08:57 AM   #2
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default

Quote:
Originally Posted by doni49 View Post
Given the following code, why is "NextKey" not available to methods in MyClass2?

I always thought that when you extend a class, all of the member methods and properties would be part of the second class--otherwise, what's the point of extending an existing class?
Try:
Code:
class MyClass1{
  public int getNextKey(){
    return _NextKey;
  }
  public void setNextKey(int val){
    _NextKey = val;
  }
  MyClass1(){
  }
  protected int _NextKey;
}

class MyClass2 extends MyClass1{
  MyClass2(){
    super();
  }
  public void doSomething(int value){
    _NextKey = value;
  }
}
__________________
My other Blackberry is a PlayBook.
Offline  
Old 10-22-2009, 11:45 AM   #3
doni49
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Default

HRB,

Thanks for that. After posting this, I found a tutorial on Sun's web site that talks about protected vs private. I'll use protected, but the reason I was TRYING to use private is that I've got other classes in the same file and I didn't want those other classes to use the other classes to have access to these properties/mthods.

I really thought that "extending" a class copied the class as sort of a starting point and that you just added new stuff or override stuff in the parent.

Oh well.
__________________
Don

Handspring Visor -> Handspring Visor Deluxe -> Palm Treo 650 on VZW -> Palm Treo 700p on VZW -> Blackberry Tour 9360 on VZW
Offline  
Old 10-22-2009, 05:45 PM   #4
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default

All object oriented languages I've used observe the same semantics, private: avaialble to no other classes, public: available to all other classes, protected: private except for "children" for which it is public.
__________________
My other Blackberry is a PlayBook.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


MSA altair 4X gas Monitor detector, O2,H2S,CO,LEL Charger calibrated picture

MSA altair 4X gas Monitor detector, O2,H2S,CO,LEL Charger calibrated

$450.00



Commercial Convection Steamer Altair picture

Commercial Convection Steamer Altair

$800.00



MSA Altair 4X multi gas Meter Monitor detector, (O2,H2S,CO) *Parts Or Repair* picture

MSA Altair 4X multi gas Meter Monitor detector, (O2,H2S,CO) *Parts Or Repair*

$200.00



MSA Safety 10087913 Charger for Altair 4X and 5X Multi picture

MSA Safety 10087913 Charger for Altair 4X and 5X Multi

$58.00



MSA 10152603 XCELL ALTAIR 2X SINGLE GAS DETECTOR O2 RPLCMNT SENSOR *NEW OPENBOX* picture

MSA 10152603 XCELL ALTAIR 2X SINGLE GAS DETECTOR O2 RPLCMNT SENSOR *NEW OPENBOX*

$239.00



MSA 10152605 XCELL ALTAIR 2X SINGLE GAS DETECTOR H2S-LC RPLCMNT SENSOR *OPENBOX* picture

MSA 10152605 XCELL ALTAIR 2X SINGLE GAS DETECTOR H2S-LC RPLCMNT SENSOR *OPENBOX*

$300.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.