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


USA Windows VPS Server / RDP Server / VPS Hosting 12GB RAM + 400GB HDD picture

USA Windows VPS Server / RDP Server / VPS Hosting 12GB RAM + 400GB HDD

$27.99



SCHNEIDER ELECTRIC PAS600 EcoStructure Panel Server Universal Wireless picture

SCHNEIDER ELECTRIC PAS600 EcoStructure Panel Server Universal Wireless

$349.00



DELL PowerEdge R210 II picture

DELL PowerEdge R210 II

$140.00



USA Windows VPS RDP Server/ Windows VPS Hosting - 4GB RAM + 150GB HDD picture

USA Windows VPS RDP Server/ Windows VPS Hosting - 4GB RAM + 150GB HDD

$11.99



New In Box MOXA NPort 5110 NPort5110 Serial Device Server picture

New In Box MOXA NPort 5110 NPort5110 Serial Device Server

$121.00



NEW Moxa NPORT 5650-8-DT RS232 422 485 Device Server picture

NEW Moxa NPORT 5650-8-DT RS232 422 485 Device Server

$864.23







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