Posts

Showing posts with the label Object Oriented Programming

Obscuring

Definition:A simple name may occur in contexts where it may potentially be interpreted as the name of a variable, a type,type parameter, or a package.(JLS-8).So it will be course to compile time error,will define as the obscuring. This is another problem that arises due to sharing the same name for a variable and a class in Java. //compile-time error in last line public class A {     public static void main(String[] args) {         String System = "Obscuring Exsample";         System.out.println(System);     } } Solution:Use Proper Naming convention.

Polymorphism Using JAVA

Image
Polymorphisam  Simply " One interface many forms " . Dispatcher decide which method will invoke in the program. If compiler dispatching(static) the method it will course to method overloading. If JVM dispatching(dynamic) the method it will course to method overriding.   (a)Method Overloading (Compile time Polymorphisam/Static Polymorphisam) Compiler is the Dispatcher in the  Same method name but different signatures. If two method of a class have the same name but signatures  not override equivalent ,then the method name is said to be overloaded. public class AppInitializer {     public static void myMethod(){         System.out.println("My method 1()");     }     public static void myMethod(int a){         System.out.println("My method 2(int)");     }     public static void myMethod(String a, int b){         System.out.println("My method 3(String, int)");     }     public static void main(String[] args) {         myMethod();// My method 1()