Q:

Java program to implement cascaded method call with an anonymous object

belongs to collection: Java Class and Object Programs

0

Java program to implement cascaded method call with an anonymous object

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Class and Object Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to check anonymous class using isAnon... >>
<< Java program to call a method using the anonymous ...