Hello, I need a output for the following code as well as screenshots from the eclipse page showing the output. Thank you public class COMP1050 { public static void main(String[] args) { System.out.printf("before"); new CS(); System.out.printf(".after"); } } public class CS extends WIT { public CS() { System.out.printf(".cs"); } } public class WIT { public WIT() { System.out.printf(".wit"); } }
Explanation: So we have two classes WIT and CIS, we also have a main class COMP1050. WIT class have a constructor which prints ".wit" and CS class extends this WIT class and also have its seperate constructor which prints ".cs".
Now in the main method first we are printing "before" and after that creating an object of CS class, this will automatically calls the constructor and will print ".wit" and ".cs", after that we will print ".after".
So the final output will be before.wit.cs.after.
Have a look at the below code and the screenshot of output.
public class COMP1050 {
public static void main(String[] args) {
System.out.printf("before");
new CS();
System.out.printf(".after");
}
}
public class CS extends WIT {
public CS() {
System.out.printf(".cs");
}
}
public class WIT {
public WIT() {
System.out.printf(".wit");
}
}
// Output: before.wit.cs.after
Happy Learning!
Get Answers For Free
Most questions answered within 1 hours.