Posts

Java OOPC - Interface

Image
  Interface Interface is keyword use in Java .Instead of using ‘class’ keyword using ‘interface’ we can create interface. As the same way creating a class we can create interface also.   Interface is also a class, but interface is not a class it work same as a class. Difference between class and interface ,interface can not   create object because of that interface even can not create constructor, But after Java 8 we can use constructors.   We can not do multiple inheritance. means that we can not inherit   more than one super class from sub class. Using extends we can not do multiple inheritance. But using the implements we can do multiple inheritance. Implements what inheritance do using the interface. So the purpose of using the interface is do the multiple inheritance. As we know we can not create the objects to the interfaces but using the upcasting we can create objects. In here object generate side be the class indeedly,   then that cla...

Java OOPC - Abstraction

Image
  Abstraction   Abstraction is that modify class or method using the ‘ abstract ’ key word. We can keep abstract method if only the class is abstract. If class is abstract there is no any difference, it is just a class. As a normal class we can work with it, means that we can use non abstract methods and variables   or anything inside the abstract class.   Meaningless we can define using the abstraction. Meaningless is that There is not any code inside the method or we can say there is not body   inside the method. In the   example, an abstract class `Animal` has been created, featuring an abstract method `makeSound()` and a non-abstract method `eat()`.   A subclass `Dog` has been derived from the superclass `Animal`. In this subclass, the abstract method `makeSound()` is implemented, providing a specific sound for a dog.   An object `d1` of the `Dog` class is then instantiated. Through this object, we invoke the methods `m...

Java OOPC -Encapsulation

Image
Encapsulation In real life capsule is based for the concept Encapsulation, We use capsule for the protection and security of the medicine that inside the capsule from   of environmental conditions and other things because that conditions generated unhealthy components.   In here when it comes to object oriented concept Encapsulation is that data hiding, protection and security. Further this concept we use for the variables.   We talk about the GET and SET methods thought the concept encapsulation,   Getters and setters   For the better security we use access modifier ‘private’   ,because in private modifier only let the specific class accessing. So private variables can use outside of the specific method using GET and SET methods.   Indeed we use private keyword for data security purpose but in some time some specific reasons we need to use those outside of the class we define it previously, Because of this reason we use getter...

Java OOPC - Polymorphism

Image
  Polymorphism     Polymorphism is the process   When Method in the sub class override the Method in the Super class, and do the upcasting after that call the   sub class method though the super class reference.   When we have multiple choices inherit the   all classes that need the super class ,after that create the meaningless method. In the end create the object as the upcasting to call sub classes. Then we can call the object for necessary data input.   Polymorphism is a fundamental concept in object-oriented programming (OOP) that allows objects of different types to be treated as objects of a common type. This not only enhances code flexibility but also promotes code reusability and maintainability.    In other simply way we can tell polymorphism as the take many forms. If we come to real world exam below show it simply. In the example, the `Calculator` class exhibits method overloading by defining multiple method...

Java OOPC - Casting

Image
  Casting   Casting is what assigning data types in hierarchical way. That means we cannot assign big type to small type data. If we said in a detailed way in we cannot assign first place data type in hierarchy to last data types in  hierarchy.     Upcasting and Downcasting     Two essential concepts in OOP are upcasting and downcasting, which involve the manipulation of object references and inheritance.   Upcasting    Upcasting involves treating an object of a derived class as an object of its base class. In simpler terms, it's moving up the class hierarchy. This is inherently safe, as every instance of the derived class is also an instance of the base class. Consider the following example in Java,   Upcasting is the   process of assigning the object from sub class to the variable in the form of Super class reference. Always object run from the class of the object created.so because of that the final...

Java OOPC - Method Overriding & Super Keyword

Image
  Method Overriding   The process of changing the body of   method that inherit From superclass to subclass is called as the Method overriding. Method overriding is a concept in object-oriented programming that allows a subclass to provide a specific implementation of a method that is already defined in its superclass.   For overriding classes should be inherit. so because of that parent class properties and behaviours are claimed to child class. In here inside the sub class same method repeat two times. One is overrided sub class method and other is inherit method from parent class. However, the overrided sub class method only runing and did not run the method inherit from parent class.   In a class first the the main method runing. Secondly   the Object is runing If we did not create any object JVM create a object from itself. Then Constructor runing and it is also if we did not create JVM itself created. Lastly normal methods are runing a...

Java OOPC - Inheritance

Image
  Inheritance   In real life inheritance is what that father and mother features genetic things got there babies also along those he or she get unique features. If we apply that to the java concept inheritance is that parent class method , properties inherit into the child classes.   In  other way can tell Inheritance allows you to create a new class that inherits properties and behaviour from an existing class. It is like that passing on the family traits . It promotes code reusability. In simply manner we can tell inheritance is how one class connect with another class.   Derived Class/Sub-class: Derived class is a class that inherits from a base class. It is also known as subclass or child class.  Base Class/Superclass:  ​ The base class is the main class where derived classes inherit the features. It is also known as the superclass or parent class.    Properties and methods in the super class inherit to the sub cl...