473,789 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1613


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.S omewierdclass 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 "instantiat es" 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******** ******@TK2MSFTN GP10.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******** *****@TK2MSFTNG P10.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
2162
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 "Some code here" class class2: propA = "A" def methB(self):
0
1277
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 C), which can be nested, and where each member can be (optionally) associated with a) a comment (as a help to the user who will enter data) and b) a unit such as kg, cm, etc. (2)variable declarations of ordinary types such as float, int, string,...
6
1739
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
7917
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 means that if I misspell a variable name, my program will mysteriously fail to work with no error message. If you don't declare variables, you can inadvertently re-use an variable used in an enclosing context when you don't intend to, or
5
8732
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 conceptually speaking : when do I define something as 'struct' and when as 'class' ? for example : if I want to represent a 'Time' thing, containing : - data members : hours, mins, secs
1
1366
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 all the common startup code for the pages on our website. It is derived from System.Web.UI.Page and every page in 2 separate projects (web applications) derives from it. It contains several declarations of server controls such a navigation bar...
8
1510
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; (I want to consider the month as part of the information contained in the node, as well as the date.) The node class also contains public member function void set_month(int) which sets the month according to the date given.
5
2036
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 of a name declared in a class consists not only of the declarative region following the name's declarator, but also of all function bodies, default arguments, and constructor ctor-initializers in that class (including such things in nested classes).
15
7873
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
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.