Thread: Strange
View Single Post
Old 01-21-2013, 08:24 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
in Java even if u import a class in a package(namespace here) u have to still instantiate(create object of) that class to access its members
Not true.

If the members are *STATIC* members, you SHOULD NOT use an instantiated object to access them. *AT MOST* you would use the class name as a prefix.

In other words:
Code:
// This is simplified Java code:
class Foo 
{
    static void Zap( String s ) { ... }
}
...
// then you should *NEVER* do
Foo f = new Foo( );
f.Zap("xyz");

// yes, it works, but it is VERY VERY misleading to do so!  
// you should instead use
Foo.Zap("xyz");
The *SAME THING* applies with VB.NET (and with C# and with any other .NET language!).

You can *EITHER* do
Code:
System.Console.WriteLine("a message")
invoking the STATIC method WriteLine *OR* you can do
Code:
Imports System.Console
WriteLine("a message")
You need to keep the distinction between static and dynamic methods and members straight.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote