Core Java Interview Question's Answers - 2
What
is overloading?
Method
- 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.
- Def-The process of writing multiple methods with the same name but with different set of parameters in terms of NOT.
- Parameter list must be different
- Return type can be anything.
- Any access modifiers.
- Static method possible.
- Early Binding
- Compile time polymorphism.
- Static Polymorphism
- Usually Within same class
Overriding.
- Def - If we want to modify the functionality of super class methods then we write the same method in subclass with diff implementation.
- Parameter list must be same.
- Return type must be same or co-variant.
- Wider or same in subclass.
- We cannot override static method.
- Late Binding.
- Runtime Polymorphism.
- Dynamic polymorphism.
- In different class.
Difference between Method and
Constructor.
Method
- This member of class contains the code describing behavior of object.
- It must have return type.
- It can have any name.
- It can have both types of return statement either empty return statement and return statement with value
- We can override it.
- We need to invoke it explicitly.
- Method recursion is there.
- No such
- Compiler never writes any method on it's own.
Constructor
- One of the 5 member of class which contains the instance initialization code.
- It can not have return type.
- It shares the name of enclosing class.
- It can have only one type of return statement i.e empty return statement.
- Since it is not inherited so we can't override.
- Jvm invokes it.
- No such
- Constructor chaining is there.
- 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.
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.
Nice Blog...Thanks for sharing the article waiting for next update...
ReplyDeleteArtificial Intelligence Course in Chennai
AI Training in chennai
ai classes in chennai
C C++ Training in Chennai
Html5 Training in Chennai
QTP Training in Chennai
Spring Training in Chennai
DOT NET Training in Chennai
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
ReplyDeleteDot 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
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
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
awesome article,the content has very informative ideas, waiting for the next update...
ReplyDeleteStudy Abroad Consultants in Kerala
study abroad consultants in thrissur
Study Abroad Consultants in Calicut
abroad job consultancy in coimbatore
Abroad Education Consultants in Coimbatore
europe job consultancy in coimbatore
study abroad
study in poland
study in europe
free masters in germany
Do you have a machine with an Apple Silicon (M1, etc.) chip? While TotalFinder is compatible with Apple Silicon, this is NOT officially supported by .TotalFinder Apple Silicon
ReplyDeleteRohos Face Logon Crack 5.4 + Activation Key Free Download 2022 from softsnew.com. Bluetooth gadget (for example, your mobile phone or a pocket PC), smart cards, .Rohos Face Logon 5.4 With Crack Free Download
ReplyDeleteOur baby is a blessing who is as beautiful as can be, Please help us welcome her into Christ's family! Come worship and celebrate with us as our daughter is .Baptism Invitation Quotes
ReplyDelete