Constructors in Java

Constructors are used to defining the object’s state. When we create an object of the class, the constructor¬†is called automatically. It is named as a constructor, because it is used to construct the value or provide the data for the objects i.e. they are used to initialize the values for the objects. Every class has Read more about Constructors in Java[…]

Nested Classes in Java

In Object Oriented Programming (OOP), an inner class or nested class is a class declared entirely within the body of another class or interface. It is different from the subclass. It is part of Java from the Java 1.1. In Java we have four types of nested classes: Static Inner class Member Inner class Singleton Read more about Nested Classes in Java[…]

Getters and Setters in Java

Getters and Setters are two conventional methods which are used for retrieving and updating the value of a variable. By the use of Getters and Setters, the programmer can control how his important variables are accessed and updated in a correct manner, such as changing the value of a variable within a specified range. Providing Read more about Getters and Setters in Java[…]

Inheritance In Java

Inheritance In Java is the process by which one object acquires the properties of another object. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. The idea of Inheritance In Java is simple but powerful, when you want to create a new class and there is already a class that Read more about Inheritance In Java[…]

Method Overloading v/s Method Overriding

The capability of more than one objects to respond to the same message in a different way can be broadly categorized into two types: Method Overloading and Method Overriding. METHOD OVERLOADING If we have methods with the same name but having different signatures or behaviors in the same scope than the methods are known as Read more about Method Overloading v/s Method Overriding[…]

What is Upcasting and Downcasting in Java

Upcasting means an object of subclass type can be treated as an object of the superclass type. Casting here doesn’t mean changing one primitive to another. Upcasting is done automatically while Downcasting needs to be done manually at the time of programming. On the other hand, Downcasting means converting a superclass type to a subclass Read more about What is Upcasting and Downcasting in Java[…]

Java Class, Objects, Methods, Constructor example – part 3

11. Example 11: class AB{int a;//instance fieldstatic int b;//class field} class A{public static void main(String[] args){ AB ab1=new AB();AB ab2=new AB();AB ab3=new AB(); ab1.a=10;ab2.a=20;ab3.a=30;ab2.b=40;ab3.b=AB.b+ab1.b; System.out.println(ab1.a+ab2.b); }} Note* : Save, Compile and Execute Output:90 12. Example 12: class B{B(int n){System.out.println(n);}void display(){System.out.println(“In display of b”);}} class C extends B{C(int b){super(b);System.out.println(b+10);} void display(){System.out.println(“In display of c”);super.display();}} class Read more about Java Class, Objects, Methods, Constructor example – part 3[…]

Encapsulation in Java

In a general language, encapsulation can be termed as “the action of enclosing something in” and in a programming language, encapsulation is used to refer to one of two related but distinct notions, and sometimes to the combination. Encapsulation is the mechanism that binds together code and the data it manipulates and keeps both safes Read more about Encapsulation in Java[…]

Contact Us
close slider
Contact Us

How can we help you with?