[quoted text, click to view] "Reny" <reny@bxtech.com> wrote in message
news:O0SMYPacGHA.4932@TK2MSFTNGP03.phx.gbl...
> Correct me if I am wrong. In an Object Oriented environment each and
> everything are objects. That means we cannot directly instantiate a class
> nor we can directly reference a member belongs to a class i.e.
> ClassName.MethodName ()
>
> If I am right in that sense, we are doing the just opposite in .NET.
Yes, .NET is fully OO but a selfrespecting language, also must support
static methods (because of class factories for instance).
But Java uses the *same* idea! How in the universe, would the runtime where
to **start** if the Main method is not static?
[quoted text, click to view] > For example in the sample Hello World Application given below
You are using VB.NET. The code below, is inside a visual basic module. By
definition, all methods in a module are static, and that's why your 'Main'
method is executable.
(if you want a real understandable OO language, use C#, and now I'm having
some people looking angry at me!)
[quoted text, click to view] >
>
> Imports System
>
> Class HelloWorld
>
> Public Shared Sub Main ()
>
> Console.WriteLine (“Hello World”)
>
> End Sub
>
> End Class
>
>
>
>
>
> As per MSDN Console is a Class defined inside the System Namespace. Here
> we are directly calling the Method () defined inside the Class Console.
> How is this possible in an OO environment?
These are all static methods. Static methods are not bad at all, only, use
them well.
I'll explain you why. If a method is static, you cannot instantiate it
right? (using Console myCons = new Console) etc
But why on earth do you want to open more than 1 console if there is only
one console -per process-?
Take this code below. It's using StreamWriter which implements the abstract
class TextWriter. Here you have your OO.
class Test
{
public static void Main()
{
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
using (StreamWriter sw = new StreamWriter("TestFile.txt"))
{
// Add some text to the file.
sw.Write("This is the ");
sw.WriteLine("header for the file.");
sw.WriteLine("-------------------");
// Arbitrary objects can also be written to the file.
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
}
}
}