create a function demo as the name of the class to get the parameters from main() function.
Answers
Answer:
Default Argument At first, display() function is called without passing any arguments. In this case, display() function used both default arguments c = * and n = 1 . Then, only the first argument is passed using the function second time. In this case, function does not use first default value passed.
Create a function demo as the name of the class to get the parameters from main() function.
Explanation:
Constructor in Java
- Special method having same as name of the class .
- Not return any value.
- Automatically called upon creating any object.
Java Program
class Demo
{
int value1;
int value2;
Demo(int v1, int v2)
{
value1 = v1;
value2 = V2;
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 obj = new Demo(56,78);
obj.display();
}
}
OUTPUT
Value1 === 56
Value2 === 78