Posts

Showing posts from October, 2020

Super keyword in java

Super Keyword in Java:- The super keyword in java is a reference variable that is used to refer parent class objects.   The keyword “super” came into the picture with the concept of Inheritance    Use of super keyword is as followed :- 1. Use of super with variables:  2. Use of super with methods:  3. Use of Super with Constructors        1. Use of super with variables:    This scenario occurs when a derived class and base class has same data members. In that case there is a possibility of ambiguity for the JVM.  We can understand it more clearly using this code snippet    class Animal {   String color="white";   }   class Dog extends Animal {   String color="black";   void printColor() {   System.out.println(color);  System.out.println(super.color);//prints color of Animal class  ...

Difference between overloading and overriding in java

S.NO Method Overloading Method Overriding 1. Method overloading is a compile time polymorphism. Method overriding is a run time polymorphism. 2. It help to rise the readability of the program. While it is used to grant the specific implementation of the method which is already provided by its parent class or super class. 3. It is occur within the class. While it is performed in two classes with inheritance relationship. 4. Method overloading may or may not require inheritance. While method overriding always needs inheritance. 5. In this, methods must have same name and different signature. While in this, methods must have same name and same signature. 6. In method overloading, return type can or cannot be be same, but we must have to change the parameter. While in this, r...

Data types in java

 Data types in Java Java has two categories of data: Primitive Data Type: such as boolean, char, int, short, byte, long, float and double Non-Primitive Data Type or Object Data type: such as String, Array, etc. Primitive Data Type Primitive data are only single values and have no special capabilities.    There are 8 primitive data types: boolean: boolean data type represents only one bit of information either true or false, but the size of boolean data type is virtual machine-dependent. Values of type boolean are not converted implicitly or explicitly (with casts) to any other type. But the programmer can easily write conversion code. Syntax: boolean booleanVar; Size: virtual machine dependent Values: true, false Default Value: false filter_none edit play_arrow ...