Unit 1: Introduction to C# Object Programming Flashcards
Object Oriented Programming definition.
OOP can be defined as a programming model which is based upon the concept of objects
Example OF Object Oriented Programming
Examples of an object, can range from physical entities: such as human beings who are described by properties( attributes)
like name and address, to small computer programs such as widgets.
What are classes?
Classes are user defined data types: that act as the blueprint for individual objects, attributes and methods.
What are Objects?
Objects are instances of a class created which specifically Define the data.
What are Methods?
Methods are functions that are defined inside a class that describe the behaviors of an object.
Each method contains in class definitions stored with a reference to an instance object.
Some cartoons contained in an object are called…..?
instance methods
What are Attributes?
Attributes represent the state of an object and are defined in the class template.
objects will have data stored in the……?
attribute field, class attributes belong to the class itself .
Methods control the…….
Movements or actions of the Object.
What is Abstraction?
Abstraction is a process where you show only” relevant” data and “ hide” unnecessary details of an object from the user.
What is Encapsulation?
Encapsulation is defined as a practice that bind data with the code that manipulates it and keeps the data and the code safe from external inheritance.
What is Inheritance?
Inheritance is the mechanism by which an object acquires the same( or all) properties of another object.
What is Polymorphism ?
Polymorphism is Ability to process objects differently based on their data type.
In other words objects can have the same name for two methods but their implementation may differ.
A visual representation Encapsulation is….?
data security
A visual representation Inheritance is….?
code reusability
A visual representation polymorphism is….?
code reusability
A visual representation abstraction is….?
hidden complexity
the object is found within…?
the class
You can use this features to withdraw the money but you never will know what exact actions are operation take place internally in the machine like after card swipe the machine check whether the card is valid or not then the pin will be verified if it is correct then only we can withdraw the money.
WHICH CONCEPT IS USED?
Abstraction
a watch you check the time many times in a day but you never need to know what the internal mechanisms of the watch is
WHICH CONCEPT IS USED?.
Abstraction
A pet class and a person class
would have a name attribute we can call within getter/setter functions that assign the value
What do you think we should use so that the code knows when the function that is being called and the variable that you are trying to assign?
Using encapsulation comes into provide a layer
When you are in a classroom , you act like a student when you are in a store, you act like a customer and when you’re at home you act like a daughter or son.
The answer is Polyomorphism since it’s different behaviors but one person
A child inherits the traits of his/her appearance
Answer: inheritance
List 3 Benefits of Object-Oriented programming
a. Reuse of Code
b. Reduction of errors
C. Faster application development
Encapsulation enables objects to be self-contained, making troubleshooting and collaborative development easier.
Modularity
The code can be reused through inheritance, a team does not have the write the same code multiple times.
Reusability
Programmers can construct new programs quicker through the use of multiple libraries and reusable code.
Productivity
Easily Upgradable and Scalable
Programmers can implement systems functionalities independently
Descriptions of external systems are simple, due to message passing techniques that are used for objects communication.
Interface Descriptions
Through using encapsulation and abstraction, complex code Is hidden, software maintenance is easier and the internet, Protocols are protected.
Security
Polymorphism enables a single Function to adapt to the class it is placed in. different objects can also pass through the same interface.
Flexibility
What are Classes Again?
Classes are user-defined data types that represent the state and behavior of an object.
What is referred to as the state and behavior?
The state represents the properties, and behavior is the action that objects can perform.
Classes can be declared using the following access specifiers that limit the accessibility of classes to other classes.
What are they?
1.Public
Public class Accounts {
} 2.Private 3.Protected 4.Internal 5.protected internal
List 4 Points about classes:
1.Classes are reference types that hold the object created dynamically in a heat
2.All classes have a base type of System.object
3.The default access modifier of a class is internal
4.The default access modifier of methods and variables is private
directly inside the namespace, declaration of private classes are not alone
If there is a need for command line arguments the user must specify the command line arguments in the Main method.
USING………
Using System;
Class GFG{
//Main method
Protected static void Main()
}
Console.WriteLine(“Main method”);
Public, private, protected, internal and protected internal access modifiers can b e used with the
Main() method.
The Main method can also have integer return type
Returning an integer value from Main()
Methods cause the program to obtain…..
status information.
The value which is returned from the Main() method is treated as the ……
exit code for the process.
Return type Example
Using System;
Class GFG{
//Main method
Static int Main()
{
Console.WriteLine(“Main method”); //for successful execution of code Return 0; }
What does namespace do?
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it.
Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.
Using System;
Class GFG{
//Main method
Static int Main()
{
Console.WeiteLine(“Main method”); //for successful execution of code Return 0; } What does namespace do?
Using System; (used to define or direct)
namespace MyNamespace
{
public class SampleClass
{
public static void myMethod()
{
Console.WriteLine(“Creating my namespace”);
}
}
}
Namespace MyProgram
{
public class MyClass
{
public static void Main() { MyNamespace.SampleClass.myMethod(); } } }
In the program the namespace is created with MyNamespace and the members are accessed from the Main() method inside MyClass.
The dot(.) operator is used to access the member of the namespace.
In the Main() method, myMethod() method is called using the dot(.) operator.
C# Output??
Console.WriteLine(“Hello World!”);
C# User Input??
string userName = Console.ReadLine();
Console.WriteLine(“Enter your age:”);
int age = Console.ReadLine();
Console.WriteLine(“Your age is: “ + age);
readline(0 returns a string so if you want it to get something else from the user an int for example you have to convert it
How do you convert user input to a number.
Int myNum = Int32.Parse(console.Readline());
ToBoolean()
Converts a type to a boolean value
ToChar()
Converts a type char type
ToDouble()
Converts a type to a double type
ToInt16()
Converts a type to a 16 bit type
ToString()
Converts a type to a string