i have differents types of ball
i have three class
i have a class plasticball
i have a class woodball
i have a class normalball
and one UserInput
i want in my main
i have 30 balls and the user to give which one of them is plasticball,which one of them is woodball and whitch is normalball.So could i do that:
Suggest you read about polymorphism, which is what this appears to be.
You define a base class Ball, then you extend from this for your three special types of ball.
You won't need any if statements then, you let polymorphism take care of which method is called, which java can do automatically based on the actual object (ball) type.
Steffe Wilson wrote:Suggest you read about polymorphism, which is what this appears to be.
You define a base class Ball, then you extend from this for your three special types of ball.
You won't need any if statements then, you let polymorphism take care of which method is called, which java can do automatically based on the actual object (ball) type.
can you give me a simple example because i didnt understand it well.