How to add class only to top level ul in main menu
That example is missing some code.  Those two empty strings should not be empty.  

There is a link on that page just above the code example to api documentation of theme_menu_tree() https://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_tree/7.x

On the api documentation page you can see it done correctly:

return '&lt;ul class="menu"&gt;' . $variables['tree'] . '&lt;/ul&gt;';