Showing posts from November, 2017

Abstraction in Java with Example Program

You must understand  Polymorphism with example , before you get into details of abstraction. Abstraction means, skipping implementation details of behavior by expressing an entity in a generic way, leaving details to be defined by subclasses. In simple words, we define classes that contain only method prototypes but not the body of the methods, the methods' body is defined by subclasses. This approach help to process objects of subclasses polymorphically. In Java, abstraction is achieved using abstract classes and interfaces. In real life, when we plan something, first we think in terms of what needs to be done, then we go into details of how  it should be done. In same way, in abstraction, we think, what behavior an entity should have and only declare that behavior (but not define it). Then, in each specific concept (or subclass), we define that behavior i.e. 'how' a specific class should act. For example, consider a student in academic system, identify common beha

Polymorphism in Java with Example Program

Before I explain polymorphism, you must understand what is generalization and specialization in context of object oriented design. Assume following classes exist in an inheritance hierarchy: Object LivingBeing Animal Pet Cat Generalization and Specialization  Assume classes are defined in a way such that, Cat extends Pet, Pet extends Animal and so on ... upto Object. You see, classes are upper side of inheritance hierarchy refers to more generic concepts as compared to classes in bottom side of hierarchy, hence the term generalization. If we look at classes defined in lower side of the hierarchy, these are more specific entities. So we say, Cat is more specific entity compared to Pet (or Pet is generic and Cat is specific). In same way, Pet is more specific compared to Animal, Animal is specific compared to LivingBeing. So, if we view classes from top to bottom of the hierarchy, we move from generalization to specialization (or from generic to specific entity). Generalizat

Task 6b - ArrayList Practice Task

Last Updated On: Nov. 17, 2020 Note: You shall try to complete below listed features. On next Thursday (Nov. 26), during online class, as Assignment 2, I would request you to add 1-2 more features in UserService class or in main method of UserServiceTest and submit me the code. To do that, you shall do this task yourself. Otherwise, you may not be able to even understand the problem statement of Assignment 2. Only the functionality implemented live would be checked, below task is just for practice and has no marks. You can ask any question to do this task during online session, because its not a weighted task. ____ Develop a menu driven application that shall allow user to choose different option numbers to add , search , update and delete users in an ArrayList object. Make a UserService class and implement different methods to perform each operation. These methods shall be called from main metod of  UserServiceTest class. The ArrayList shall be defined as private instance variable in