Program/Source Code:
The source code to implement a cascaded method call with an anonymous object is given below. The given program is compiled and executed successfully.
// Java program to implement cascaded method call // with the anonymous object class Sample { Sample Method1() { System.out.println("Method1 called"); return this; } Sample Method2() { System.out.println("Method2 called"); return this; } Sample Method3() { System.out.println("Method3 called"); return this; } } public class Main { public static void main(String[] args) { new Sample().Method1().Method2().Method3(); } }
Output:
Method1 called Method2 called Method3 called
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program/Source Code:
The source code to implement a cascaded method call with an anonymous object is given below. The given program is compiled and executed successfully.
Output: