473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

class declarations - basic question

I noticed that there are two ways I declare classes:

1. public class xxxx { }
2. Somewierdclass myClass;

The 2nd example exists provided I have a 'using' statement at the top that
includes that class from some place. I am wondering, why does the 2nd way
not require a scope (ie public) ? And why doesn't it require the keyword
'class'. Is it because 'class' denotes an empty.NET class, whereas
Somewierdclass is something that already exists.

I am guessing thats also why the 1st example has brackets & the 2nd doesn't.
Because the first example is an empty .NET class and the members of the
class are defined in the { } 's. But the 2nd example is a ready-built class
from somewhere else, and so we can't add on members to a pre-existing class
coming from somewhere else, hence no brackets?

Thanks for any correction / confirmation of the above
Jason Shohet
Nov 15 '05 #1
4 1595


1. public class xxxx { } 2. Somewierdclass myClass; The 2nd example exists provided I have a 'using' statement at the top that includes that class from some place.
You could also place:

SomeNamespace.Somewierdclass myClass;

instead of

using SomeNamespace;

Somewierdclass myClass;

I am wondering, why does the 2nd way
not require a scope (ie public) ?
Each variable where you don't declare a scope is automaticly set to private.

Somewierdclass myClass == private Somewierdclass myClass
And why doesn't it require the keyword 'class'. Is it because 'class' denotes an empty.NET class, whereas Somewierdclass is something that already exists.


You use 'class' only when you are declaring a class... Not when defining

A variable of that type.

You would use

Public class myClass

{

....

}

And then somewhere else:

myClass myVar = new myClass

Or something similar.

Hope this helps,

Saso
Nov 15 '05 #2
The first example is how you DEFINE a class. Think of a class as a blueprint
to a house. A blueprint is not the same thing as an ACTUAL house. This class
definition is the blueprint.

The second example is how you define a datatype, that will hold a class. In
actuality, you would need to do this:

Someweirdclass myClass = new Someweirdclass();

This says that the myClass variable will be of type "Someweirdclass" and it
also "instantiates" an "instance" of that class.

A class definition is like the blueprints to a house - while an instance is
much like an actual house. You could say that a house is an "instance" of
what the blueprint described.

hth

" Jason Shohet" <as****@hotmail.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
I noticed that there are two ways I declare classes:

1. public class xxxx { }
2. Somewierdclass myClass;

The 2nd example exists provided I have a 'using' statement at the top that
includes that class from some place. I am wondering, why does the 2nd way
not require a scope (ie public) ? And why doesn't it require the keyword
'class'. Is it because 'class' denotes an empty.NET class, whereas
Somewierdclass is something that already exists.

I am guessing thats also why the 1st example has brackets & the 2nd doesn't. Because the first example is an empty .NET class and the members of the
class are defined in the { } 's. But the 2nd example is a ready-built class from somewhere else, and so we can't add on members to a pre-existing class coming from somewhere else, hence no brackets?

Thanks for any correction / confirmation of the above
Jason Shohet

Nov 15 '05 #3
Thank you, great explanation.
Actually Saso I think you meant, you use 'class' only when you are defining
a class... Not when declaring a class (that already has been defined
somewhere else) ?

You use 'class' only when you are declaring a class... Not when defining

A variable of that type.

Nov 15 '05 #4
yeah... that's it :) I mixed up declared and define :)
I'm glad it helped...

Saso
" Jason Shohet" <as****@hotmail.com> wrote in message
news:uJ*************@TK2MSFTNGP10.phx.gbl...
Thank you, great explanation.
Actually Saso I think you meant, you use 'class' only when you are defining a class... Not when declaring a class (that already has been defined
somewhere else) ?

You use 'class' only when you are declaring a class... Not when defining

A variable of that type.


Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: OKB (not okblacke) | last post by:
For a variety of reasons, I'm interested in putting together some code that will allow me to created structures out of nested classes, something like: class class1: def methA(self): print...
0
by: Rikard Land | last post by:
I try to model a data definition language in XML. It can be seen as C without any executable statements other than variable assignments. I want to allow for: (1) type declarations ("structs" in...
6
by: SearedIce | last post by:
Consider the following simplified hypothetical code: #include <iostream.h> class rabbit { public: rabbit() {x = 3; y = 3; /*code here to set field to 1*/} void runtocage(); int x;
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
1
by: Chris | last post by:
This may be more of a Visual Studio question but those groups seem to be full of unrelated stuff so hopefully this might be the right place. I have a class (no associated aspx file) which handles...
8
by: pauldepstein | last post by:
I am writing a program which looks at nodes which have coordinates which are time-dependent. So I have a class called node which contains the private member declarations int date; int month; ...
5
by: Steven T. Hatton | last post by:
If find the following excerpt from the Standard a bit confusing: <quote> 3.3.6 - Class scope -1- The following rules describe the scope of names declared in classes. 1) The potential scope...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.