Java

Let’s learn methods in java. Methods in java A block of code to perform a certain operation or particular task is method. Method is declared inside a class with method name followed by parentheses ( ). A method executes only when it is called. We have some predefined methods in java such as sqrt(), pow()…

Read More Methods in java

Let’s learn Strings in java. Strings in java A String is an object in java. It is not a primitive type. For example: String name = “Sachin”; java.lang.String class implements Serializable, Comparable and CharSequence interfaces. NOTE: String object is immutable. Once created a String object cannot be changed. There are two ways to string object.…

Read More Strings in java

Let’s learn nested classes in java. Nested classes in java A class inside another class is known as nested class. A nested class can be private. Syntax: class A // outer class { …… class B // nested class { ….. } } Nested classes in java are divided into two, they are – Static…

Read More Nested classes in java

Let’s learn abstraction in java. Abstraction in java Abstraction is defined as hiding internal implementation and showing only necessary information. There are two ways to achieve abstraction in java, To create an abstract class and abstract method in java “abstract” keyword is used. “abstract” is a non-access modifier. Here’s abstraction in java with example. //…

Read More Abstraction in java

Let’s learn inheritance in java. Inheritance in java Inheritance is a procedure of acquiring all the properties and behaviour of a parent class (super class) into child class (subclass). It is achieved by using “extends” keyword. Inheritance represents “IS-A” relationship between super class and subclass. By inheriting we are reusing all the methods, properties and…

Read More Inheritance in java

Let’s learn access modifiers in java. Access modifiers in java Access modifiers sets the visibility of a variable, constructor, class or a method. There are two types of modifiers in java; access modifiers and non-access modifiers in java. There are four types of access modifiers in java; private access modifier, protected access modifier, public access…

Read More Access modifiers in java

Let’s learn this keyword in java. this keyword in java this keyword is reference variable that refers to the current object. It is required when we have a local variable with same name as an instance variable of the class. Let me explain this keyword in java with an example. class Demo { int m;…

Read More this keyword in java

Let’s learn constructor in java. Constructor in java Constructor is a special method or block of code used to initialize an object. It executes automatically when you create an object. Example: class DemoClass { // constructor name is same as class name DemoClass() { …. } } // calls DemoClass() constructor DemoClass obj = new…

Read More Constructor in java

Let’s learn polymorphism in java. Polymorphism in java Polymorphism literally means many forms. Polymorphism is the ability of a method to perform different tasks. It can be achieved through method overloading and method overriding. For example: Wood has many forms table, chair, dinning table etc. Example : Polymorphism in java class Shapes { public void…

Read More Polymorphism in java

Let’s learn classes and objects in java. Classes and objects in java Class is a template or a blueprint or a prototype. Class is a collection of objects. Syntax: access-modifier class ClassName { // fields // constructors // methods } In the below code the public keyword is an access modifier that we use to…

Read More Classes and objects in java