• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Inheritance - How Casting Works (Equipment) (Ball) new SoccerBall();

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package org.otsi.scottselikoff.jeanneboyarsky;

abstract class Ball {

protected final int size;

public Ball(int size) {
this.size = size;
}

}

interface Equipment {

}

public class SoccerBall extends Ball implements Equipment {

public SoccerBall() {
super(5);
}

public Ball get() {
return this;
}

public static void main(String[] passes) {

Equipment equipment = (Equipment) (Ball) new SoccerBall().get();
System.out.println(((SoccerBall) equipment).size);

}

}
 
Saloon Keeper
Posts: 13248
291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Do you have a question?

When posting code, please put it inside code tags like [code]this[/code]. It will make your code look like this:

 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic