Javatpoint Logo
Javatpoint Logo

F# Object and Class

F# is a functional programming language. It also supports object oriented programming approach and allows us to create class and object.


F# Object

Object is a real world entity. It can be anything like ? cell phone, car, football etc.

Object is an instance of class. We can access all the members of class by using object of this class.

Let's see an example of how to create object in F#.

In the above example, objectName is the name of object which refers to class. New is a keyword which is used to allocate memory for object. ClassName is a name of class of which we are creating object.


F# Class

Class is a template or blue print of an object. It is used to encapsulate data members and member methods. It can contain fields, methods, constructors, static methods etc.


F# Class Example

This F# class example has two fields and one method only. We have displayed field values in this method by using object.

Output:

12 FSharp

F# Initialize and Display Data through Method

Output:

25 RajKumar
26 John
27 Mariam

F# Class Example: Store and Display Employee information

Output:

25 RajKumar 25000.00
26 John 26000.00
27 Mariam 27000.00

F# Calling Instance Variable in another Class Example

Output:

102 Rajkumar
Next TopicF# Constructor




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA