Pages
- Home
- About
- 1.Java - Language Fundamental
- 2.Java - Operator & Assignments
- 3.Java - Flow Control
- 4.Java - Access Modifiers
- 5.Java - OOPs Concept
- 6.Java - Exception Handling
- 7.Java - Multithreading
- 8.Java - Garbage Collection
- 9.Java - java.lang Package
- 10.Java - java.io package
- 11.Java - Collection Framework
- 12.Java - Enum
- 13.Java - Generics
- 14.Java - Assertions
- Java Programming Questions
- Today's Laptops & Mobiles Hot Deals
- Install java(jdk) & Set path & Run program
Flipkart add sale
Java- Polymorphism / Chapter - 9 / OOP's Concept
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
Difference between Method Overloading and Method Overriding
- Method Names: - In Overloading method name should be same, And Even In Overriding method name should be same.
- Argument Type: - In Overloading, argument type must be different (at least the order of arguments), But in the Overriding argument type must be same.
- Method Signature: - In Overloading, method signature must be different, But in the Overriding method signature must be same.
- 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 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:-
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:-
- Two methods are said to be overloaded method if and only if ,both methods having same name but different arguments types.
- 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.
- 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
1. In Java method signature consists of, methods names followed by arguments types.
2. Return Type is not part of the method signature in java.
3.The compiler will use method signature to resolve method calls.
example:-
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");
}
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
Inheritance
- It is also known as Is-A relationship.
- The main advantage of inheritance is code reuse-ability.
- 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:-
- It is also known as Is-A relationship.
- The main advantage of inheritance is code reuse-ability.
- 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- 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:-
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:-
Subscribe to:
Posts (Atom)
© Copyright 2017 Javabychetan.blogspot.com |