Computer Applications
Differentiate between the following statements:
abc p = new abc();
abc p = new abc(5,7,9);
Java Constructors
27 Likes
Answer
The first statement abc p = new abc();
is calling a non-parameterised constructor to create and initialize an object p of class abc. The second statement abc p = new abc(5,7,9);
is calling a parameterised constructor which accepts three arguments to create and initialize an object p of class abc.
Answered By
17 Likes
Related Questions
Distinguish between parameterised constructor and non-parameterised constructor.
Name two ways of creating objects in a constructor.
Fill in the blanks to design a class:
class __________{
int l, b;
Area(int __________, int __________) {
l = __________;
b = __________;
}
}Write a program by using a class with the following specifications:
Class name — Hcflcm
Data members/instance variables:
- int a
- int b
Member functions:
- Hcflcm(int x, int y) — constructor to initialize a=x and b=y.
- void calculate( ) — to find and print hcf and lcm of both the numbers.