I mean oxygen is electronegative element it should have negative oxidation number Also how it is able to make bond with fluorine which itself is electronegative? Why the oxidation number of oxygen is +2.?
Oxygen is an electronegative element -True.
But oxygen is not the most electronegative element. It has an electro negativity of 3.5 on Pauling scale. That means if oxygen combines with an element which is more electronegative than it will surely possess a positive oxidation state.
Fluorine being the most electronegative element (electro negativity of 4.0 on Pauling scale) will in any case (except in fluorine gas) have an oxidation state of -1. So that's the reason why oxygen has a +2 oxidation state in OF2.
Dioxygen difluoride (O2F2) is another fluoride of oxygen in which oxygen has an oxidation state of +1.
EDIT: Fluorine in its gaseous form (F2) has zero oxidation state.
Fluorine is more electronegative than oxygen. Thus it would attract electrons towards itself during complete transfer. It would result in a +2 charge on oxygen. Thus oxygen has +2 oxidation no.