Core Java Interview Question's Answers - 2

  What is overloading?
  • The process of writing multiple methods with the same name in a class is known as Method Overloading.
  • Here parameter list must be different in terms of Number or Order or Type of parameter(NOT).
  • Method name and parameter list together is known as Method Signature so in short we can say in case of Overloading Method Signature must be different. 
  • Method Signature does not include Return type of method so Return type can be anything.
  • Method Overloading is also known as Early Binding or Compile Time Polymorphism or Static Polymorphism.
  • It is known as Early Binding because from the invocation statement which actual version of methods will be invoked, this binding is made earlier the execution of program by  the compiler.
  • It is known as Compile Time Polymorphism because Compiler is making decision during the Compilation process about which exact methods.
What is overriding?
  • If we are not okay with the method implementation in super class then we can re-implement in sub class, this process of modifying the existing functionality is known as Overriding.
Restrictions on the particular method of subclass while Overriding.
  • Name should be same.
  • Parameter list should be same.
  • Return type should be same if primitive or same or sub (co-variant) if reference.
  • Static method is Hidden not Overridden but we need to follow the rules of Overriding.
  • Instance method should be Overridden as instance method only.
  • Access modifier should be same or wider but not narrower.
  • Final method cannot be Overridden.

Difference between Overloading and Overriding.
Overloading.                                                                                       
  1. Def-The process of writing multiple methods with the same name but with different set of parameters in terms of NOT.
  2. Parameter list must be different                        
  3. Return type can be anything.                             
  4. Any access modifiers.                                           
  5. Static method possible.                                       
  6. Early Binding                                                          
  7. Compile time polymorphism.                            
  8. Static Polymorphism                                           
  9. Usually Within same class                                    
Overriding.
  1. Def - If we want to modify the functionality of super class methods then we write the same method in subclass with diff implementation.
  2. Parameter list must be same.
  3. Return type must be same or co-variant.
  4. Wider or same in subclass.
  5. We cannot override static method.
  6. Late Binding.
  7. Runtime Polymorphism.
  8. Dynamic polymorphism.
  9. In different class. 
Difference between Method and Constructor.

Method                                                                                      
  1. This member of class contains the code describing behavior of object.   
  2. It must have return type.                                     
  3. It can have any name.                                          
  4. It can have both types of return statement either empty return statement and return statement with value                         
  5. We can override it.                                                 
  6. We need to invoke it explicitly.                        
  7. Method recursion is there.                                 
  8. No such                                                                   
  9. Compiler never writes any method on it's own.   
Constructor
  1. One of the 5 member of class which contains the instance initialization code.
  2. It can not have return type.
  3. It shares the name of enclosing class.
  4. It can have only one type of return statement i.e empty return statement.
  5. Since it is not inherited so we can't override.
  6. Jvm invokes it.
  7. No such
  8. Constructor chaining is there.
  9. Compiler writes default if no constructor is written inside a class.            
What is Import?
  • Import is keyword in java.
  • It is used to import classes.
  • If we don’t import then we need to refer that class with fully qualified class name that will make the code lengthy and reduce the readability of code.
  • There are two type of import statement. 
               1 - Explicit Import or single import
               2 -Implicit import or multi import.
  • Java.lang package is automatically imported in all java files.
  • Import statement should appear after package statement.
What is static import?
  • If we want to import only static members of a class but not the whole class then we can use static import.
Syntax to import static members of a class.
  • import static dhiraj.chandra.com.Person.age;
  • Here also we have two types
             1 - Single or explicit.
             2 - Multi  or Implicit.
  • By using this kind of import since we are not importing the whole class so we can’t create object of that class.

Comments

  1. Nice! you are sharing such helpful and easy to understandable blog. i have no words for say i just say thanks because it is helpful for me



    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery





    ReplyDelete
  2. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details. thansk for ur next post
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete

Post a Comment

Thank You for reading our post.
Your comment or feedback encourages us to improve the quality of content.
Don't forget to follow/subscribe to get the latest post.

Popular posts from this blog

Mobileum Bangalore Core Java Developer Interview

Xylem bangalore : Senior Java Developer.

Learning Java For Interview Purpose. Day - 1