Two constructors in one class in JavaA class may include several constructors. The constructors' parameter lists, however, shouldn't be identical. Overloading of constructors is what this is called. It is demonstrated by the following program: ConstructorExpl.java Output: Let's now examine the aforementioned software. The data member num and the single member function display() that shows the value of num are the building blocks for the NumberValue class. The class NumberValue has two constructors, one of which accepts no parameters while the other of which accepts a single int parameter. The following code snippet illustrates this: The display() function is called on the objects o1 as well as o2 of the class ConstructorExpl that are created in the main() method. Here is a sample of code that illustrates this: Next TopicUnion in Java |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India