[ajug-members] casting

Rob Worsnop rworsnop at gmail.com
Tue Jul 1 16:49:15 EDT 2008


The answer to your first question is Yes. To your third, No.

But might I suggest that the next step in your continuing Java
education should be to invest the time it takes to download a JDK?
Then you'll be able to try these things for yourself.

On Tue, Jul 1, 2008 at 4:12 PM, 521 <521 at ofig.org> 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
>



More information about the ajug-members mailing list