Javatpoint Logo
Javatpoint Logo

Dart Callable Classes

Dart provides the facility to call class instances like a function. To make callable class, we need to implement a call() method in it. Let's understand the following example -

Example - 1

Output

Dart Callable class
Student name is Sharma and Age is 18

Explanation:

In the above code, We defined a call() function in the class Student that takes two arguments String name, integer age and return a message with this information. Then, we have created the object of class Student and called it like a function.

Let's have a look at another example -

Example - 2 Multiple callable class

Output

Dart Callable class
Student name is peter and Age is 18
Employee id is 101 and Age is 32

Explanation:

In the above code, we defined two callable functions in class Student and class Employee. The Employee class call() function accepts two parameters as String empid and int age. We called instances of both classes as callable functions.


Next TopicDart Isolates





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA