January 2018

Java Copy Constructor

  • Satish 

1. Introduction A copy constructor in a Java class is a constructor that creates an object using another object of the same Java class. That’s helpful when we want to copy a complex object that has several fields, or when we want to make a deep copy of an existing object. 2. How to Create a Copy Constructor To create a copy constructor, we can first declare a constructor that takes an object of the same type as a parameter: public class Employee { private… Read More »Java Copy Constructor

Anonymous Classes in Java

  • Satish 

1. Introduction In this tutorial, we’ll consider anonymous classes in Java. We’ll describe how we can declare and create instances of them. We’ll also briefly discuss their properties and limitations. 2. Anonymous Class Declaration Anonymous classes are inner classes with no name. Since they have no name, we can’t use them in order to create instances of anonymous classes. As a result, we have to declare and instantiate anonymous classes in a single expression at the point of use. We may… Read More »Anonymous Classes in Java