("Area: " + shape. Then simply loop unitList & call respective methodsįor calculating Area for (Shapes shape : unitList) Get inputs from the user & add to the above list. Then you need to have one list static List unitList = new ArrayList() Method overloading is used to achieve compile-time polymorphism. The types of polymorphism in Java are mentioned : compile-time (static) polymorphism and runtime (dynamic) polymorphism. Polymorphism means many forms or many shapes. Then I want to save them in a unit list and call my classes methods ,which are calculateArea and calculatePerimeter and show perimeter and area of them with their name. This allows for the creation of code that can operate on objects of different classes in a consistent and predictable manner. A variable of a superclass type can reference an object of a subclass type. The number of shapes it depends on the user. What ever wants ,For example 3 Circles ,2 Rectangles and 7 Squares. Armed with our knowledge of inheritance, polymorphism, Javas wrapper classes ( 13.4). I want to get required data for each of above classes and create them by user. to all shape objects to compute some useful result for example.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |