Shrikiran11 / Js_css_Bootstrap

0 stars 0 forks source link

Declaring constructor final #1

Open Shrikiran11 opened 2 years ago

Shrikiran11 commented 2 years ago

class Employee {

int id = 123;

final Employee() {
    id = id - 2;
}

}

class Company { public static void main(String[] args) { Employee em = new Employee(); } } //Exception in thread "main" java.lang.Error: //Illegal modifier for the constructor in type Employee; only,protected & private are permitted

Shrikiran11 commented 2 years ago

//Exception in thread "main" java.lang.Error: //Illegal modifier for the constructor in type Employee; only,public protected & private are permitted