![]() ![]() From Java 8, they can also have concrete methods in the form of default and static methods thus reducing the gap between abstract classes and interfaces. Till Java 8, interfaces are allowed to have only abstract methods. In the above code snippet, Interface has anIdea() which is implemented by ClassOne and ClassTwo according to their requirements. ("An idea is implemented according to ClassTwo requirement") For example : The components of your smartphone are wrapped ( encapsuled) up into single unit and is presented as a whole phone to the ("An idea is implemented according to ClassOne requirement").In Java encapsulation is achieved by access modifiers eg.Wrapping up of fields, objects, and method within a single unit called class is known as encapsulation.These details have been hidden from the driver and only important details like steering, gear lever, brake etc. For example : When driving a car driver just turn steering, changes gear but driver don’t know about how steering is working inside, how gears are shifting.Abstraction in Java is achieved by interface and abstract class.Data abstraction refers to the way of showing only necessary information to the use and hiding any complex implementation details.For example : Animals can create many sound like howl, meow, growl, grrrr etc.In Java we can achieve polymorphism either by method overloading ( Compile time Polymorphism) or by method overriding ( Run-time Polymorphism).‘ Polymorphism’ is a Greek word meaning ‘poly’ means many and ‘ morphs’ means form hence called ‘many forms’. Polymorphism is defined as the ability of a message to take more than one from.For example : Children inherit from parents, their properties and behavior.Inheritance provides code re usability, helps in extending the properties of a class and helps in achieving run-time polymorphism.When one class called child class derive the properties of another class called parent class, then this is called inheritance.Class is a blueprint which contains fields and methods that define state and behaviour of objects. Class is a user defined data type too.Seeing above example we can say that class is a group of similar type of objects.Hence BMW is a class and BMW 5 series is an object of BMW class. Now collection of these cars have same state and behavior and belong to the same class called BMW.Its identity is BMW 5 series, state is its black color and behavior is that it runs on road. Hence Object can be defined as a real world entity that has identity, state and behavior.So you can extract some attributes from the objects around you and they are their state, behavior and identity.For example : pen, mobile phone, table, chair, you yourself etc. Any physical entity around you is an object.Okay! Now what you think is a class and what might be an object? Any guesses? We shall see this below.These concepts are somehow logical and can be implemented easily which results in better function-ability of the software. OOPs in java provide some concepts which help in simplifying software development. ![]()
0 Comments
Leave a Reply. |