Q: Is Constructor Overloading is possible in Java? ================================================== Do we able to define more than one constructor in a class? =========================================================== package Java.IO.AIT; class ABC{ public ABC() { System.out.println("This is a default constructor."); } public ABC(int x) { System.out.println("This is Parameterized Constructor."); } } public class ConstructorOverLoad { public static void main(String[] args) { ABC aobj = new ABC(); ABC bobj = new ABC(100); } } ======================================================= Dynamic Polymorphism: ==================== ==> also called as "run-time polymorphism". Method Overriding: ================== ==> when the child class/sub class required to re-define the parent class/super class method in this case "Method Overriding" is required. ==> To implement the method overriding, the inheritance is mandatory. ==> Overriding is not possible within the same class. ==> During the method overriding, the child class can completely replace the behavior of the parent class method which is inherited from parent class to child class. Note: ===== During the method overriding, the signature of parent class method and child class method must be same but the implementation (method body) can differ. class A{ void m1(int x, int y) { x+y; } } class B extends A{ void m1(int x, int y) { x * y; } } default ==> Package private ==> class public ==> anywhere protected ==> Package public >> protected >> default >> private ==> During the method overriding, the access modifiers for the child class method must be either same level or more than parent class method's access modifiers. package Package.Io.Java; class Class1{ void m1() { System.out.println("m1() is in parent class."); } // public void m1() // { // System.out.println("This the method."); // } } class Class2 extends Class1{ // @Override public void m1() { // super.m1(); System.out.println("m1() is in child class."); } } public class MainClass { public static void main(String[] args) { // Class2.m1(); // Class1.m1(); Class2 c1 = new Class2(); c1.m1(); } } ex:1 ==== class A{ void m1() // default { stat1; stat2; } } class B extends A{ public void m1() { implementation } } =================== class A{ public void m1() { } } class B extends A{ public void m1() { } } ==> During the method overring, the return type of the child class method is same as parent class or covariant type. class A{ public double m1(int x){ } } class B extends A{ public double m1(int x) { } } ================================== class Employee{ public Employee m1(int x) { } } class FullTimeEmployee extends Employee{ public FullTimeEmployee m1(int x) { } } class PartTimeEmployee extends Employee{ } ==> During the method overriding, the method name must same as the parent class method. ==> The number of parameters, order of parameters and type of parameters during the method overriding is not same as the parent class method. ==> the static method of parent class never be override in child class. If we have define the same static method of parent class in child class after the inheritance, this is possible with "method hiding". Method Hiding ==> hiding the parent class static method and make execute the child class static method is called as "method hiding". ==> @Override ==> is a Java SE Annotation which is used to instruct the compiler that the method which specifies is overriding. package Package.Io.Java; class Class1{ static void m1() { System.out.println("m1() is in parent class."); } // public void m1() // { // System.out.println("This the method."); // } } class Class2 extends Class1{ // @Override static void m1() { // super.m1(); System.out.println("m1() is in child class."); } } public class MainClass { public static void main(String[] args) { Class2.m1(); Class1.m1(); } } =============================================== @Override: ========== package Package.Io.Java; class Abc{ void doCaliculationForTax() { System.out.println("doCaliculationForTax() from parent class."); } } class Def extends Abc{ @Override void doCalculationForTax() { System.out.println("doCalculationForTax() from Child Class."); } } public class Main { public static void main(String[] args) { Def d = new Def(); d.doCaliculationForTax(); } } ======================================================= 1) Is static method overloaded within the same class? 2) Is constructor of the class override? 3) Is static method override? 4) Explain @Override?