Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
plz tell me what is the difference between instance and object i dont understand still the difference between these two

2) also tell me what is abstract class and why we use abstract class
3) what is static and why we use static keyword
Posted
Updated 14-Sep-11 9:33am
v2
Comments
wizardzz 14-Sep-11 15:34pm    
This is obviously homework. If you're going to cheat. Use Google, or are you looking for an ungoogleable answer so you don't get caught?

These are 3 completely different questions, too.
[no name] 14-Sep-11 15:45pm    
I am thinking it is Interview questions... And it wouldn't be ungooglable once the answer is posted ;)
wizardzz 14-Sep-11 15:51pm    
I thought that, too. I still use homework as a blanket term for all that.

 
Share this answer
 
1) An instance refers to an existing object, where as an object is the type.

Think of it this way,
A car is the object, but the instance is the one you drive (versus the one I drive).


2) An abstract class allows an inherited class to use polymorphism (overloading). It also allows logic that all inheritted members will have.

For example a Car may be the abstract class but Sedan and Sporty will use it for a parent class. The "Car" abstract class will likely impliment the logic for MPH as it is the same regardless of whether is is a Sedan or a Sporty car.


3) Static means no instance is necessary. For example the Car abstract type referred to earlier may actually inherit Vehicle which has a property WheelCount. The Car static type would result in 4 where as MotorCycle would return 2. There is no need to have the Sedan instance track this as all instances of all Cars will have the same wheel count. So one would likely set the value of the wheel count in an abstract static Car constructor or some initialization method.
 
Share this answer
 
v6
Comments
KenBonny 15-Sep-11 2:46am    
I don't get the votes for 2. I think this is well structured, provides one example throughout the entire post so you know what we're talking about and it doesn't use that much advanced terminology.

The only reason I didn't give a 5 is because you didn't specify that you shouldn't use an abstract class as an instance, only as a type that is initialised with a sub class. Example:

abstract class Car {}
class Sedan : Car {}
class Program {
public static void Main() {
Car c = new Sedan();
}
}
object is the class variable with memory assign to all its fields but no value set between them and instance is a object of class at run time when all fields get value assign example
public class cls
{
public string name{get;set;};
public string roll{get;set;};
}

then object represent in memory as

name point to memory

roll point to memory

and instance represent in memory as

name point to memory where value "Ganesh" is store in name

roll point to memory where value "1" is store in roll
 
Share this answer
 
Comments
BillWoodruff 9-Dec-14 6:34am    
You have answered a question asked three years ago; did you realize that ?
Ganesh Gadekar 4-Jan-15 23:38pm    
Yes my dear friend i have added comment that will be helpful for needy person who search this question in future.Don't you wanna help them.
Member 13639418 23-Jan-18 12:30pm    
@Ganesh Gadekar you were righ..ur ans is one of all other answers which helped me a lot to understand...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900