home / developersection / tag
uppose we are required to create an application that generates a random list of odd numbers. The list itself should consist of a random number of entr
One more benefit of constructor overloading is the ability to create a copy constructor, which allows us to create an object copy from the values of another similar object.
The protected ModifierGoing back to our asset management example, we have defined several classes that lie in a single hierarchy. The Asset, BankAccou
The public ModifierPreviously we understand the visibility of members at certain level using access modifiers in java. Now here we see public modifier
We know java uses four access modifiers public, protected, default and private to maintain visibility at various levels. Let’s discuss how to define t
In the examples so far, we have seen the use of the public and private keywords. These are access modifiers that control the visibility of fields, methods, and classes in the scope of the entire application.
Earlier we created and used variables of the class type that hold references to the objects of those class types. Now, we’ll cover an important situation in which such a variable of the class type is declared final.
Just the way we create final classes, we create final methods that cannot be overridden in the subclasses. To explain the purpose behind this, let’s look at an example.
The package statement allows us to group logically related classes into a single unit. In our earlier programs, we have used import statements such as the following:
All of us have observed inheritance in nature. For example, a baby inherits the characteristics of her parents; a child plant inherits the characteristics of its parent plant, and so on.
To better understand the object-creation process, let’s begin with a simple case of two-level inheritance, where we have just a base class and its derived class.
In our example of the previous post, the classes Asset, BankAccount, and SavingsAccount defined two constructors. Both constructors obviously have the