A virus can get on your computer many ways, we will cover one of those ways right now.
When you browse the Internet the websites a website that you go to has been compromised and is spreading viruses. This could be through advertisements or the site has been hacked. When a hacker gains access to a site they put code on it that takes advantage of out of date versions of plugins. There has been many examples of this from small sites to a big commercial site like NBC's site.