you could get 50 points if u can solve it.
In java programming, define a constructor function for a 'Date' class that initialize the 'Date' objects with given initial values. In case initial values are not provided, it should initialize the object with default values.
Answers
Answer:
If initial values are given:
Also assume that variables d,m,y are previously declared.
Date(14,07,2019)
{
d=14;
m=07;
y=2019;
}
If initial values are not given:
Date()
{
d=0;
m=0;
y=0;
}
Hope it helps... please mark as brainliest...
Explanation:
hi mate,
Answer:
What is Constructor in Java:-
CONSTRUCTOR is a special method that is used to initialize a newly created object and is called just after the memory is allocated for the object. It can be used to initialize the objects to desired values or default values at the time of object creation. It is not mandatory for the coder to write a constructor for a class.
If no user-defined constructor is provided for a class, compiler initializes member variables to its default values.
numeric data types are set to 0
char data types are set to null character(‘\0’)
reference variables are set to null
In this tutorial, you will learn-
Rules for creating a Constructor
Constructor Overloading
Constructor Chaining
Rules for creating a Java Constructor
It has the same name as the class
It should not return a value not even void
Example 1: Create your First Constructor Java
Step 1) Type following code in your editor.
class Demo{
int value1;
int value2;
Demo(){
value1 = 10;
value2 = 20;
System.out.println("Inside Constructor");
}
public void display(){
System.out.println("Value1 === "+value1);
System.out.println("Value2 === "+value2);
}
public static void main(String args[]){
Demo d1 = new Demo();
d1.display();
}
}
Step 2) Save , Run & Compile the code. Observe the output.
Output:
Inside Constructor
Value1 === 10
Value2 === 20
i hope it helps you.