• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to type cast and what is instance of operator .  RSS feed

 
Saad Sadiq
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create an abstract class Shape. Create a class Circle that extends Shape with data
member radius of type double, define a parameterized constructor . Create another class
Triangle that extends Shape with data members base & height of type double.Define a
constructor with two parameters. Create a class TestShape and write printAreas method
that scans along the myShapes array and uses casting as well as the instanceof
operator to print out the area of each shape.After casting the object access the radius for
type Circle and base & height for Triangle tocalculate the area.Write a method
printName and print if the instance is of a circle or a triangle. Create a method doStuff()
in same class and instantiate myShape array of size 3. Fill the values 2 for circles and
one for triangle with the help f parameterized constructors. and call the methods
printName() & printAreas().In main class create th object of type TestShape and call
doStuff().[TYPE CASTING using INSTANCEOF operator]
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You're commenting on the words mentioned in the last sentence. Have you got what is in the first sentence?

However, read here, and here (<- actually don't read latter, it is Java Language Specification, can be very hard).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!