Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between objects and classes in C#? [duplicate]

Tags:

c#

.net

oop

class

Possible Duplicate:
Difference between object and instance

I have couple of questions:

  1. Every instance of a class (except an abstract class) is an object?
  2. Abstract classes cannot be instantiated, hence they are not objects?

Could anyone help me better understand the above concepts as they relate to C#?

like image 326
user793468 Avatar asked Dec 18 '11 06:12

user793468


1 Answers

class Cat {} // It is a cat. Just a cat. Class is a general issue.

myCat = new Cat("red", "5kg", "likes milk", "3 years old"); // It is my cat. It is an object. It is really a cat. 

yourCat = new Cat("gary", "3kg", "likes a meal", "5 years old"); // It is your cat. Another cat. Not my cat. It is really a cat too. It is an object;

abstract class Animal {} // Abstract class
animal = new Animal(); // It is not correct. What is 'animal'? Cat, dog, cow? I don't know.

class Dog : Animal {} // It is a class. It is a dog in general. 
someDog = new Dog("brown", "10 kg", "likes cats"); // It is really a dog. It is an object.
like image 169
ceth Avatar answered Oct 15 '22 10:10

ceth