package com.vedantkakade;
class Student {
String fname;
String lname;
public void printInfo() {
System.out.println(fname + " " + lname);
}
Student(Student other) {
this.fname = other.fname;
this.lname = other.lname;
}
}
public class temp {
public static void main(String[] args) {
Student s1 = new Student(); //Error: constructor Student in class com.vedantkakade.Student cannot be applied to given types;
Student s2 = new Student(s1);
}
}
Why java is not giving me default construct? When I am only specifying the copy constructor. And if I add the default constructor and remove the copy constructor then also it is giving me error. Why it is not giving me required constructor. what i know is that java provides copy constructor if we dont specify the constructor and if we dont specify and constructor then it gives me default constructor
New contributor
Vedant Kakade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.