Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

C# and oop


  • Please log in to reply

#1
BuRnEr

BuRnEr

    Member

  • Member
  • PipPip
  • 48 posts

hi guys i m back afrer sometime(by the way i m CompTia :)
;)
hey brner i red all of your explanations about the languages actually i m learning C# in .net enviroment but i have a problem about polymorfism,inheritance,abstract class or methods and also i cant make my asp.net work.could you give some help here...(i m running windows xp pro on my computer)
thanks to everybody from now who ll atend to help!!!

;) smiley days :)

View Post

firs i created different topic because this topic is totally differet where you posted your answer, and may other people can add something extra :

here it is:


Hi Black Sea !!!

First of all I would like to say that oop (object oriented) is big concept as I said before, and inheritance and polymorphism are feature of oop. there are many and many tutor out there about that ….
You asked about Inheritance and Polymorphism?
And secondly you are asking about setting up ASP.net and its not unusual question and I am not surprised because it is hard work to set it up(even for advance) it needs some work to done…

I will try to give your answers with definition and examples,
Inheritance:
Think cat class (by the way I am veterinarian,…believe me)
Lion class
Leopard class
Jaguar class
Golden class and so on.

The primary characteristic of the animals on the above is that they are cats in the same class but different category. Another point they share is that is they are animals. On the other hand, although these cats have different characters like tail length, legs length, teeth structure, body size. The class would appear as:

Class cat
{
CategoryOfCat;
Body Size;
}

If you want to create class to represent these cats, you may be tempted to implement a general class that defines each category. This may be a bad idea because, despite their body resemblance, there are many internal differences among these cats. Programming languages (oopl) like C#, java, C++, and other(oopl) provide an alternate solution to this type of situation.

Inheritance consist of creating a class who we primary definition or behavior is based on another class. In other words, inheritance starts by having a class that can provide behavior that other classes can improve on.

NOTE:!!!!!!!
C#, like java and contrary to C++, allows only single class inheritance. Multiple inheritances of classes are not allowed in C#.
If you were using a language such as C++ you could easily inherit from both classes using multiple inheritances.
Structures (struck) in C# can only inherit (or implement) interfaces and cant be inherit.
And if you don’t want your class to be inherited by any class, you can mark it with the sealed keyword. No class can inherit from a sealed class.

On Practice:
inherit.cs
class main
{
public static void Main()
{
child a=new child();
a.abc();
}
}
class parent //based class
{
public int i = 10;
public void abc()
{
System.Console.WriteLine("in parent abc");
}
public void pqr()
{
System.Console.WriteLine("in parent pqr");
}
}
class child :parent //driven class(in child)
{
public void abc()
{
System.Console.WriteLine("in child abc");
base.pqr(); //calls the base class` method which is pqr in parent
}
}
Output
In child abc, In parent pqr

Base.pqr(), calls the pqr() in parent class. If you don’t use it in there it does not call pqr() in parent class and the output will be only in child abc.
If you don’t have the method abc in child class than it will use the method abc which is in parent class.
As a short you re a calling in main function a.abc(), if it is not find abc() in child class it will look in base class and when it finds than executes that method.
I tried demonstrated all possibilities.

Polymorphism
It is little bit tricky:
MSDN explanation: “Polymorphism is the ability for classes to provide different implementations of methods that are called by the same name. Polymorphism allows a method of a class to be called without regard to what specific implementation it provides.”

On Practice:
polymorphism.cs
class main
{
public static void Main()
{
parent a=new parent();
child b =new child();
parent c=new child();
a.abc();a.pqr();a.xyz();b.abc();b.pqr();b.xyz();c.abc();c.pqr();c.xyz();
}
}
class parent //based class
{
public virtual void abc() //virtual method
{
System.Console.WriteLine(“in parent abc”);
}
public virtual void pqr() //virtual method
{
System.Console.WriteLine(“in parent pqr”);
}
public virtual void xyz() //virtual method
{
System.Console.WriteLine(“in parent xyz”);
}
}
class child : parent //driven class(child)
{
public override void abc()
{
System.Console.WriteLine(“in child abc”);
}
public new void pqr()
{
System.Console.WriteLine(“in child pqr”);
}
public void xyz()
{
System.Console.WriteLine(“in child xyz”);
}
}
Output
In parent abc, in parent pqr , in parent xyz, in child abc, in child pqr, in child xyz, in child abc, in parent pqr, in parent xyz

Little explanation see the keywords “virtual, override, new” ….

Object c was initialized by a child object and hence it first goes to class child. Here the function has a modifier override which in Engilish means, forget about the data type of c which is parent , call abc from child as it overrides the abc of the base class. The override modifier is needed as the derived class functions will get first priority and be called. I mean to override the abc of the base class.
New has the exactly the opposite meanings. The function pqr has the new modifier.c.pqr() calls qpr from parent and not child. New means that the function qpr is a new function and it has absolutely nothing to do with the pqr in the base class.


Abstract Classes
Abstract classes can be simply defined as incomplete classes.
1-Abstract classes contain one or more incomplete methods called abstract methods.
2-The abstract class only provides the signature or declaration of the abstract methods and leaves the implementation of these methods to derived or sub-classes.
I would give an example about it later for now I guess is enough for you take rest……  but you can find good explanation in here :
http://msdn.microsof...lrfabstract.asp
about setting up ASP:
I don’t know what kind of problem you have but this is common problem everybody has it and I had it 2years ago when I try to set up vs.net first my machined, before asp I was using perl CGI and I can say that asp is much more better than CGI programming.
If there is a better technology why don’t I use it…
So now lets see what can we do for setting up asp hhhh
of course if you dont have IIS installed you MUST install it first. Installing IIS
->controlpanel->add/remove prog->add windows components (left side)-
>check ISS box and click next with inserting xp pro cd to your cd
room drive and next for installing.
After installing first thing you have to check that if your asp net is working or not
so (mostly not)if it is working there is no problem and go ahead and its ready to serve you....lucky cat:)
second its not working :tazz:
1-when you open your IE browser and type "//localhost" in address
section and see what happended if you get error ;
says http 500 --->that error code means you dont get real error code
for getting real error code follow this steps:
on IE->tools->internetOPtions->advance-> and if it is check "show
friendly error messages" check box under Browsing. and ok
try to type localhost again and enter and see the error code!!!
2-if it gives you the error[code=cannot_......] so you have to make
sure that you re using proxy server or blah blah...
on IE tools->internet options->connections->lan settings->uncheck the
check box option of "automaticly detect settings"..(Idiot IE)
and type "//localhost" IE browser address bar... working?
You still have problem? if yes and says version of .net the error says "version 1.1....blah blah " so its need to be updated run the windows updater and update it then restart your machine. still getting same error don’t worry after install the updates you have to transfer your updates to .net and install it again how : lets see now how ...
start->programs->Microsoft visual studio .net->visual studio .net
tools->visual studio .net command prompt black and ugly screen pop up
and type in : "aspnet_regiis /i" and it started to install it and
after it says installed than close your ugly black screen and go to
open your visual studio and new project asp.net web application under (vb or c# or...) and

Whooolaa
mine is working and yours should be:)

"when i was 15, i had a dog its name was bingooooo!!!!!!!!
take care now
if there is any comment let me now haaa my number is still
128.144.2.1,443,(RTT=˘Ŕ*RTT_old+(1-˘Ŕ)*RTT_new, 0<˘Ŕ<1)
  • 0

Advertisements


#2
BlackSea

BlackSea

    Member

  • Member
  • PipPip
  • 54 posts
hey Burner Thank you!!!you re awosome :tazz:
and everybody should read this tutorial...now i know and i can implement inheritance, and polymophsm in my codes too.....

little more help?? asp.net working fine but i cant open the applications with ie ,,,,,,,,,
actually there is a one more problem i ve got about asp.net, well i created my first aplication in asp.net but now i cant open it with my ie browser..i checked everything but when i click on application it opens it in .net or gives me error...
so can you helpme about that ....

and i would like to say this team is great ...whenever i ask something i get my answer. thanks to everybody also specially thanks to admin(site administrator) tooo...

smily days
never forget to smile
  • 0

#3
BlackSea

BlackSea

    Member

  • Member
  • PipPip
  • 54 posts
ups i found the problem about asp it was about permitions(i have to add asp users permition list), now everythings fine :tazz:

thanks thanks to everybody
smilie days ;)
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP