public static void main(String[] args) { System.out.println(new Welcome()); } }
1. It will compile and run perfectly and product output as "Value of counter is 10"
2. It will compile and run perfectly and product output as "Value of counter is 0"
3. Code will not compile as no valid Welcome(int) method is defined.
4. Code will not compile because, you are trying to restrict the visibility of toString() method.
5. As we know, every class by default extends the Object class. Which has public toString() method. Hence, you cannot restrict the access modifiers for the overridden method.