473,563 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

private static

What is the purpose or difference between
private static and private method in non-static class?
Nov 18 '05 #1
5 1638
If I understand you correctly, you want to know the difference between a
private static method in a non-static class, and a private non-static method
in a non-static class? If I am correct in my understanding of your
question...

A non-static class is a class which requires instantiation to use. A
non-static member of a class is a member which requires an instantiation of
its host class to use. A static member of a class is a member which does NOT
require an instantiation of its host class to use.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"TomislaW" <to*********@ho tmail.com> wrote in message
news:uS******** ******@tk2msftn gp13.phx.gbl...
What is the purpose or difference between
private static and private method in non-static class?

Nov 18 '05 #2
Kevin's right and to build on it...a public static method in an instance
class often provides utility functionality to the outside which somehow
relates to the class. For example, given a User class, you might have a
public static method to say, get a user class by user id:

public class User{
private int userId...

public static User GetUserById(int userId){
}
}

A private static method in an instance class pretty much does the same, but
only exposes the functionality internally to the class. In my experience,
the need for this doesn't come up too often. I've probably used it the most
when I provider overloads of public statics and they all use the same
private static, that for some reason I don't want exposed.. Just my $0.02

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:OG******** ******@TK2MSFTN GP15.phx.gbl...
If I understand you correctly, you want to know the difference between a
private static method in a non-static class, and a private non-static method in a non-static class? If I am correct in my understanding of your
question...

A non-static class is a class which requires instantiation to use. A
non-static member of a class is a member which requires an instantiation of its host class to use. A static member of a class is a member which does NOT require an instantiation of its host class to use.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"TomislaW" <to*********@ho tmail.com> wrote in message
news:uS******** ******@tk2msftn gp13.phx.gbl...
What is the purpose or difference between
private static and private method in non-static class?


Nov 18 '05 #3
I think the confusion lies in that a static method, as you say, does not
require an instantiation of the host class, but being private, nothing can
access it but an instantiation of the host?!

Therefore, would it be right to suggest that there's never a reason for
using private and static together in declaring a function?
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:OG******** ******@TK2MSFTN GP15.phx.gbl...
If I understand you correctly, you want to know the difference between a
private static method in a non-static class, and a private non-static
method
in a non-static class? If I am correct in my understanding of your
question...

A non-static class is a class which requires instantiation to use. A
non-static member of a class is a member which requires an instantiation
of
its host class to use. A static member of a class is a member which does
NOT
require an instantiation of its host class to use.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"TomislaW" <to*********@ho tmail.com> wrote in message
news:uS******** ******@tk2msftn gp13.phx.gbl...
What is the purpose or difference between
private static and private method in non-static class?


Nov 18 '05 #4
Dan Bass wrote:
I think the confusion lies in that a static method, as you say, does
not require an instantiation of the host class, but being private,
nothing can access it but an instantiation of the host?!

Therefore, would it be right to suggest that there's never a reason
for using private and static together in declaring a function?


You can call private static methods from other static methods
(possibly public) in that same class.

Hans Kesting
Nov 18 '05 #5
Hans,

For some reason I thought this wouldn't compile because the statics weren't
both public!
cheers for that.

"Hans Kesting" <ne***********@ spamgourmet.com > wrote in message
news:Ob******** ******@TK2MSFTN GP15.phx.gbl...
Dan Bass wrote:
I think the confusion lies in that a static method, as you say, does
not require an instantiation of the host class, but being private,
nothing can access it but an instantiation of the host?!

Therefore, would it be right to suggest that there's never a reason
for using private and static together in declaring a function?


You can call private static methods from other static methods
(possibly public) in that same class.

Hans Kesting

Nov 18 '05 #6

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

Similar topics

3
5382
by: IHateSuperman | last post by:
public class StaticField2{ public static void main(String args){ private int x, y; // <<== error 1 for ( y = 0 ; y < 100 ; y++){ x = StaticMethod(); System.out.println(" x = "+x); } } public static int StaticMethod(){ private static int m = 0; // <<== error 2
34
3074
by: Andy | last post by:
1) Is there any use of defining a class with a single constructor declared in private scope? I am not asking a about private copy constructors to always force pass/return by reference. 2) Is this in any way used to create singletons. Can someone say how? Cheers, Andy
4
6117
by: baumann | last post by:
hi all, according the private / protected access control, - private; that is, its name can be used only by members and friends of the class in which it is declared. - protected; that is, its name can be used only by members and friends of the class in which it is
21
4383
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a...
8
2609
by: nytimescnn | last post by:
I've read some discuession about lock() for thread-safe. I am wondering what will be the differce between below two code segment? Code 1: class A { private static Object padlock = new Object(); ...// some codes
6
2186
by: VSP | last post by:
Hello, I am just implementing singleton pattern in various ways. In one implementation I created a static member and returning that static member in the getInstance() function. I have made constructor as private and destructor as public. class Single { private:
5
1964
by: Stodge | last post by:
I've exposed a C++ class to Python using Boost Python. The class, let's say it's called Entity, contains private static data, which is an array of strings. Though I think it implements it using MFC's CPtrArray. I've also exposed a public function from Entity - let's say it's called foo. This function accesses the private static data (the...
1
6839
by: romand | last post by:
EDIT: ***SOLUTION FOUND*** Just to check, before I had the 2 functions in the second code box I used in the main the logger function and when I got it to be private I haven't erased the lines in the main. ********* Question: hello, If you remember me from yesterday, having some problems. I've defined a helpFunctions.cpp class with static...
0
7658
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...
0
7579
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...
0
8101
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...
0
6235
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...
1
5479
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5201
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...
0
3628
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...
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
909
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...

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.