Showing posts with label oops. Show all posts
Showing posts with label oops. Show all posts

Class and object in c# with real time example

In this tutorial, I am going to discuss about the "real-time example of Class and object in c#". To understand object and class concepts read this post carefully.

What is OOPS..?
Object-oriented programming (OOP) is a programming structure where programs are managed by objects, classes and it ’s action and logic. C# provides full support for 
object-oriented programming including encapsulation, inheritance, and polymorphism.

Class and object in c# with real time example

Class and object in c# with real time example

If we talking about the class in any language, a class is just a user define data type used to represent the relation between the data and functions or methods.

A class can have many things like variable, function, properties. In another way, we can say that class is a block of code where we can define the state and behavior of objects, function, and variables.

Note: By default class is internal.

See below Syntax Format:

Class class name



Here I am taking an example of c# class.

using System;   //namespace

class Employee
    public string name;
    int age;
    string address;

    public string departmant()           //method define by me
      return "I.T.";
    static void Main(string[] args)      //Main method

      Employee emp = new Employee();   //Object creation of Employee class = "Jhon";
      emp.age = 10;
      emp.address = "Delhi";
      Console.WriteLine(" "+emp.age+" "+emp.address+" "+emp.departmant());

In the above example, we can see that our method and variable are exits in class.

Object: An object is basically an instance of the class. It allocated the memory to access the member of the class. An object is a real-time entity.
 If we want to access the class member we need to create an object of that particular class.
In the below example, we take ‘Employee’ as a class then ‘emp’ are the object.

Syntex for Object:

ClassName objectname=new ClassName();


Employee emp = new Employee();   //Object creation of Employee class
In the above syntax, the ‘new’ operator is used to create an object of a class. When we create an object, then the system creates the memory for data members and methods that are present in the class.

Important Point to remember 
An object is the base type of all classes in the dot net framework. This object can hold any kind of value, however, boxing will be done implicity and unboxing need type casting mechanism.

Also Read: 
                 Boxing and Unboxing With Simple Example
                 Lockdown SQL Course

Read More

[Solved] Jquery datepicker set value in textbox ( and Html Control)

Jquery date picker 

Today I going to show you how you set value in textbox using the Jquery date picker in or any other control (like HTML). Here we take a simple HTML textbox to pick a date using Jquery UI, in this process we use 3 ajax-official script link.Here we need to match the id of HTML Textbox $("#HTMLtxtbox").datepicker(); with the jquery id selector. If you want to implement date picker with textBox then try this $('#<%=ASPtxtbox.ClientID%>').datepicker();

Jquery datepicker set value textbox

<html xmlns="">
    <link rel="stylesheet" href="//">
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script src=""></script>
    <script src=""></script>
        $(function () {

            //For HTML TextBOX
            $("#anim").on("change", function () {
                $("#HTMLtxtbox").datepicker("option", "showAnim", $(this).val());

            //For Asp.Net TextBox
            $("#anim").on("change", function () {
                $('#<%=ASPtxtbox.ClientID%>').datepicker("option", "showAnim", $(this).val());
    <form id="form1" runat="server">
                    <td>Jquery DatePicker With TextBox</td>
                        <asp:TextBox ID="ASPtxtbox" runat="server"></asp:TextBox>
                    <td>Jquery DatePicker With HTML TextBox</td>
                        <input type="text" id="HTMLtxtbox" />


Read More

Encapsulation In Java With Realtime Example

Introduction to Encapsulation in Java: In this tutorial, I am going to discuss about the "real-time example of encapsulation in java" hope it will helpful for you.

Encapsulation: [A mechanism which is to hide information (Data or Implementation)] Here, the capsule means it is just a container or we can say that a structure that enclose a body part (function or class).

Encapsulation in java with realtime example
Img: Wikipedia

Encapsulation is a process of binding data member (like variables, properties) and member function (like methods) into a single unit. If we talk about class and function it is the best example of encapsulation in java.

In other words, encapsulation is the process of hiding the internal details of an object. We can achieve encapsulation by hiding details using the access modifier (Public, Private, Protected, Default).

class Students          //No matter there is union or struct
public double totalMarks;  //data, variable or attribute
   public double MarksScored; 

   Public double GetPercentageMarks()      //operation
       double Percentage =(MarksScored /totalMarks) * 100;
       return Percentage;


Students OOpsStd = new Students(); 

In the above code we have encapsulated totalMarks, MarksScored and Method GetPercentMarks. While creating a "OOpsStd" object, the implementation of  GetPercentMarks will not be shown.


A function is also Example of Encapsulation

void add()
    int a = 4;
    int b = 5;      //data, variable or attribute
    int  c;

    c =  a + b;       //operation

    cout << "Addtion of 2 no is: " << c;



Why we use Encapsulation in java

1) We can control the way of data accessibility.
2) Later on, you can modify the code at your end.
3) Encapsulation in java helps us to achieve loosely couple.
4) The main goal of Encapsulation is to achieve simplicity in our application.
5) Encapsulation in Java allows you to change one part of the code without affecting another part line of code.

Encapsulation in java with real-time example:

Encapsulation in java with realtime example

Encapsulation play a major role by developing the application the literal meaning of abstraction or the simplest mean of show the operational part or providing the operational part to the use is abstraction and encapsulation is hiding the complexity from the user is set to be the encapsulation 


We can say if there is a encapsulation there will we abstraction if we place an order for mobile to X company customer or  user is only consort for operation the mobile like brightness , volume ,SMS,call,power off he is not caller of the internal component of the mobile like electrical part of handset, how touch screen made he doesn't know that's encapsulation. He only knows functioning part of mobile or operational part of mobile this call abstraction.

Read More

Operator Overloading in C# Definition with example

Operator Overloading in c# Example 

In this article, I am going to discuss about operator overloading and it's example, Sometimes developers confused about it and they think operator overloading and function overloading is same but both are very different.

Definition of Operator overloading

The class allows creating a user to define the type or extract datatype. If we create a variable of that type is set to be an object but that object doesn't support all the operators it supports few operators like . and (Assignment operator), by using operator loading we can enhance the capabilities of an object to support the operator.

1. Operator overloading works on early binding approach.
2. We can't operator overload at that function which approaches decide at run-time.

Why we use operator overloading in c#
Used for to achieve object addition.

Steps for implementing operator overloading in c#
Here is some step that you need to follow while you are implementing operator overloading in c#.

1.The operator is a function is to be applied to support inbuilt operator to given an object
2.The opeartor function should be static(See Example).
3. This function always takes two parameters, can't have three parameters and must be public.
4.Note: We can't overload AND, OR, NOT like logical operator.
5. Operator function returns the object of containing class.

Example of Operator overloading

using System;
class office
    double salary;
    public office()
        salary = 0;
    public office(double sal)
        salary = sal;
    public void Display()
    public static office operator +(office o,office ob//it must be public static otherwise get compiler error
        office obj = new office();
        obj.salary = o.salary + ob.salary;
        return obj;

    static void Main()
        office a = new office(1212);
        office b = new office(7888);
        office accuntant = new office();
        accuntant = a + b;



Read More