[ajug-members] casting

521 521 at ofig.org
Wed Jul 2 08:25:16 EDT 2008


Marc, Bjorn, Rob, Jeff, and Dave: thanks, this helps - I just learned form 
what each of you have said that my first question's answer is 'Yes'- (which 
is why I had 'symbol' errors with my jdk efforts) which invalidates (in a 
sense) my second question- thanks to each of you- 

barclay

On Tue, 1 Jul 2008 17:01:33 -0400, Marc Lawson wrote 
> If you want   the Subtractor class to be able to use the showadder()   
> method in Adder then you need to have subtractor extend Adder..... 
> 
> public class Subtractor extends Adder{ 
> } 
> 
> On Jul 1, 2008, at 4:12 PM, 521 wrote: 
> 
> > can I only cast up/down a hierarchy? 
> > 
> > per below, what would the syntax be in order for a 'Subtractor'   
> > object use 
> > the Adders classes' showadder method?  would it be like this- to cast 
> > Adder 'type' on the sub object- that is, in order to get to an Adder's 
> > method? (Adder)sub.showadder 
> > 
> > 
> > [code] 
> > public class ProgramDisplayer { 
> >     public static void main(String args[]) { 
> >           System.out.println("Hi!"); 
> > 
> >          Adder add = new Adder(); 
> >          add.showadder(); 
> > 
> >          Subtractor sub = new Subtractor(); 
> >          sub.showsubtractor(); 
> >     }      
> > } 
> > [/code] 
> > [code] 
> > public class Adder{ 
> >     public void showadder() { 
> >          int low = 0;int high = 9;int count=low; 
> >           while(count<high){System.out.println(count);count  ;} 
> >     } 
> > } 
> > [/code] 
> > [code] 
> > public class Subtractor { 
> >     public void showsubtractor() { 
> >          int low = -10;int high = 0;int count=high; 
> >           while(count>low){System.out.println(count);count--;} 
> >     } 
> > } 
> > [/code] 
> > 
> > Thanks, 
> > 
> > Barclay 
> > 
> > 
> > 
> > _______________________________________________ 
> > ajug-members mailing list 
> > ajug-members at ajug.org 
> > http://www.ajug.org/mailman/listinfo/ajug-members 
> 
> _______________________________________________ 
> ajug-members mailing list 
> ajug-members at ajug.org 
> http://www.ajug.org/mailman/listinfo/ajug-members




More information about the ajug-members mailing list