Class & Object are the basic concepts of Object Oriented Programming which revolve around the real-life entities.
In C#, classes support the polymorphism, inheritance and also provide the concept of derived classes and base classes.
Interfaces in Object Oriented Programming Languages, An interface is a programming structure/syntax that allows the computer to enforce certain properties on an object (class).
2. Contents
Introductions
Definition of Class, Object & Interface
Adding variable & methods into Class
Class member access modifiers & Constructor
Creating objects & accessing class member
Static Member for class
Creating & Implement interface into class
Distinguish between Class, Object & Interface
Questions
3. Introduction
Class & Object are the basic concepts of Object Oriented Programming which revolve
around the real-life entities.
In C#, classes support the polymorphism, inheritance and also provide the concept of
derived classes and base classes.
Interfaces in Object Oriented Programming Languages, An interface is a
programming structure/syntax that allows the computer to enforce certain properties
on an object (class).
4. Definition of Class
Class:
A class is like a blueprint of specific object. A class enables you to create your own
custom types by grouping together variables of other types, properties, behavior,
methods and events etc. Define an interface by using the class keyword.
Example- Every object has some color, shape and functionalities etc.
Syntax:
public class MyClass
{
//Here are Properties, Methods & Events
}
5. Definition of Object
Object:
An object is basically a block of memory that has been allocated and configured according
to the blueprint of the class. A program may create many objects of the same class.
Objects are also called instances and they can be stored in either a named variable or in an
array or collection. Define an interface by using the new keyword.
Example:
Customer, Student, Mobile Phone & Car etc.
Syntax:
BankAccount account = new BankAccount()
6. Definition of Interface
Interface:
An interface is like an abstract base class. Any class or struct that implements the interface must
implement all its members. An interface can't be instantiated directly. Its members are implemented by
any class or struct that implements the interface. Interfaces can contain events, indexers, methods,
and properties. Define an interface by using the interface keyword.
Interfaces in C# are a means to get around the lack of multiple inheritance in C#, meaning you can’t
inherit from multiple classes but you can implement multiple interfaces.
Example: All bank account holders can be operate cash withdrawal & deposit commonly.
Syntax:
interface IMyInterface
{
// contain events, indexers, methods, and properties here…
}
10. Static Member for a class
“static” means “relating to the type itself, rather than an instance of the type”. You access a static member using the
type name instead of a reference or a value, e.g. DateTime.Now()
In addition to methods and variables, you can also declare a class to be static (since C# 2.0). A static class cannot be
instantiated and can only contain static members.
12. Distinguish between Class, Object & Interface
Class Object Interface
A class describes the attributes and
behaviors (Blueprint) of an object.
An object is the instance of the class to
use variables and methods from inside the
class.
An interface contains behaviors that a
derived class implements it.
A class may contain abstract methods,
concrete methods & constructor.
A class may contain variables and
methods.
An interface contains only abstract methods
& Doesn’t contains constructor.
Members of a class can be public, private,
protected or default.
Internal is the default if no access
modifier is specified.
All the members of the interface are public
by default.
Classes have logical existence. Objects have a physical existence.
Interface have logical existence.
A class doesn't take any memory spaces
when a programmer creates one.
An object takes memory when a
programmer creates one.
A interface doesn't take any memory
spaces but only for carry on reference.
The class has to be declared only once. Objects can be declared several times
depending on the requirement.
The interface has to be declared only
once.
15. Try to Resolve
What is class?
What is object?
What is interface?
Difference between Class & Object?
Difference between Class & Interface?
Why we use static keyword?
How static member is accessed?
What is the benefits of interface?
Can you explain about constructor & deconstructor?
Can you create an instance of an interface?
Can you create an instance of an abstract class?
Why we can’t create an object of an abstract class?
Why we can’t specify the accessibility modifier for methods inside the interface?
Is it possible can have multiple methods in a single class?
Is it necessary for abstract class to have abstract method?
When do you favor abstract class over interface?