Java- Object Type Casting / Chapter - 10 / OOP's Concept

java Object Type Casting

Now that we have learned that,


We can use parent reference to hold child object.


example:-     Object  o   =  new String ("javabychetan");


We can use interface reference to hold child object implemented class object.


example:-     Runnable      r   =  new Thread ( );


let's understand the syntax of "How to do Type-Casting".

Java Object Type Casting

Before Doing type casting we have to apply or check all these three rules otherwise, we won't able to perform type casting.


Java- Polymorphism / Chapter - 9 / OOP's Concept

Java-Polymorphism

Polymorphism


One into many forms is the concept of polymorphism.


example 1: - method name is same but we can apply for different types arguments(Overloading).

public void m1(int)                  (Overloading)

public void m1(long)               (Overloading)

public void m1(float)                (Overloading)
example 2: - method signature is same but in parent class one type of implementation and in the child class another type of implementation(Overriding).

Java- Difference Between Method Overloading & Method Overriding / Chapter - 8 / OOP's Concept

Method Overloading,Method Overriding Difference between Method Overloading and Method Overriding 



  1. Method Names: - In Overloading method name should be same, And Even In Overriding method name should be same.

  2. Argument Type: - In Overloading, argument type must be different (at least the order of arguments), But in the Overriding argument type must be same.

  3. Method Signature: - In Overloading, method signature must be different, But in the Overriding method signature must be same.

  4. Return Type: - In Overloading, there is no restriction on the return type, But in Overriding return type must be same until 1.4 v, But from 1.5v onwards co-variant return type is allowed.

Java- Method Overriding / Chapter - 7 / OOP's Concept

Method OverridingMethod Overriding in Java


1.In java, whatever method parent class has that method by default available to the child class through inheritance. If the child class is not satisfied with parent class method implementation then child class is allowed to redefine that method based on its requirement, this process is known as "Overriding".


2.The parent class method which is overridden is called overridden method and the child class method which is overriding is called the overriding method.


3.In overriding method resolution is always takes care by JVM based on the runtime object hence overriding is also known as runtime polymorphism or dynamic polymorphism.


Java-Method Overloading / Chapter - 6 / OOP's Concept

Method Overloading
Method Overloading:-


Two methods are said to be overloaded method if and only if, both methods having the same name but different arguments types.
In the old language like C method overloading concept is not available hence, we can't declare multiple methods with same name but different arguments types.
But in Java, we can declare multiple methods with same name but different arguments types.Such type of methods is called the overloaded method. This overloading feature of java reduces the complexity of programming.

Java- Overloading / Chapter - 6 / OOP's Concept

Overloading:-

  1. Two methods are said to be overloaded method if and only if ,both methods having same name but different arguments types.
  2. In old language like C method overloading concept is not available hence ,we can't declare multiple methods with same name but different arguments types.
  3. But in Java , we can declare multiple methods with same name but different arguments types.Such type of methods are called overloaded method. This overloading feature of java reduces the complexity of programming.                                                                                                                                        example:

    class Test
    {
             public void m1( )
             {
                 System.out.println( "no - arguments m1() method");
             }
               public void m1( int   x)
              {
                 System.out.println( "integer - arguments m1() method");
              }
              public void m1( double y)
              {
                 System.out.println( "double - arguments  m1() method");
               }
           public static void main( String [ ] args)
            {
                      Test    t   =   new    Test( );
                       t.m1( );
                       t.m1(20 );
                       t.m1(20.5);
              }
    }

    Output is:

Java- Method Signature / Chapter -5 / OOP's Concept



   Java- Method SignatureJava Method Signature



    1. In Java method signature consists of, methods names followed by arguments types.

Method Signature Syntax

     2. Return Type is not part of the method signature in java.
     3.The compiler will use method signature to resolve method calls.

example:-

Java- Method Signature / Chapter -5 / OOP's Concept

1. In Java method signature consists of, methods names followed by arguments types.


     2. Return Type is not part of method signature in java.
    3.Compiler will use method signature to resolve method calls.

example:-
class Test
{
        public void m1(int i)
       {
             System.out.println(int  type arguments");
         }   
        public void m1(String s)
       {
             System.out.println(String type  arguments");
         }   
        public static void main(String [ ] args )
        {
               Test   t    =new  Test( );
               t.m1(10);
               t.m1("javabychetan");
        }
}

Output

Java Inheritence / Chapter -4 / OOP's Concept


Java Inheritance

Inheritance



  1. It is also known as Is-A relationship.

  2. The main advantage of inheritance is code reuse-ability.

  3. By using extends keyword we can implement Is-A relationship.


example:-

class P

{

     public void m1()

    {

        System.out.println("Parent");

     }

}

class C extends P

{

   public void m2( )

   {

       System.out.println("Child");

    }

Class Test

{

     public static void main(String [ ] args)

    {

            C c =new C ( );

            c.m1( );

            c.m2( );

      }

}

 Output is:  


Java- Inheritence / Chapter -4 / OOP's Concept



Inheritance:-

  1. It is also known as Is-A relationship.
  2. The main advantage of inheritance is code reuse-ability.
  3. By using extends keyword we can implement Is-A relationship.
example:-
class P
{
     public void m1()
    {
        System.out.println("Parent");
     }
}
class C extends P
{
   public void m2( )
   {
       System.out.println("Child");
    }
Class Test
{
     public static void main(String [ ] args)
    {
            C c =new C ( );
            c.m1( );
            c.m2( );
      }
}
 Output is:  Parent
                   Child
            
Conclusion:-
  • Whatever method parent class has by default available to the child class and hence on the child reference we can call Both Parent & Child class methods.

Java- Encapsulation / Chapter -3 / OOP's Concept



Java Encapsulation

Java Encapsulation



  1. The process of binding the data and corresponding method into a single unit is nothing but "encapsulation".                  

  2. If any component follows data hiding and abstraction such type of component is said to be encapsulated component.


Java- Encapsulation Java- Encapsulation

The main advantage of encapsulation are:-



Java- Encapsulation / Chapter -3 / OOP's Concept

  1. The process of binding the data and corresponding method into a single unit is nothing but "encapsulation".                  
  2. If any component follows data hiding and abstraction such type of component is said to be encapsulated component.

Java- Abstraction / Chapter -2 / OOP's Concept



Abstraction

Abstraction:-


Hiding internal implementation and just highlighting the set of services what we are offering, is known as "Abstraction". 
example:-
Through Bank ATM GUI screen bank people are highlighting the set of services what they are offering without highlighting internal implementation.
Abstraction


The main advantage of Abstraction are:-




Java- Abstraction / Chapter -2 / OOP's Concept

Abstraction:-

Hiding internal implementation and just highlighting the set of services what we are offering , is known as "Abstraction".
example:-
Through Bank ATM GUI screen bank people are highlighting the set of services what they are offering without highlighting internal implementation.



The main advantage of  Abstraction are:-

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com