I am new to civicrm.
I have created a module; say com.ex.myextention. and created a page its working fine.
But in my module where I have to write a hook and how to ensure the defined hook is working.
"To implement a hook, add a function to the module's main .php file created earlier with civix generate:module" - the developer guide.
However, if you've created your own page class, you may not need to use a hook at all, since you have complete control of the code.
If I haven't answered your question, please update your question with a bit more detail about what you're trying to do.