473,378 Members | 1,375 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,378 software developers and data experts.

private static void Main()

In Java, the Main method cannot have any other access modifier than 'public'. How is it that in C# you can have a private access modifier to the Main method ? Can anybody throw any light, comparing JVM with CLR

Thanks
Sujala
Nov 15 '05 #1
3 11968
Hi,

If you refer to Main method as the entry point of the application, then you
have a similar situation in C# than in Java, in c# the entry point MUST be
declared as
static void Main() , if that is not present the compiler will give you an
error.

Now there is nothing that prohibite you to name a method Main() on any
class, only that it will no be the entry point of the application.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Sujala" <su*******@hotmail.com> wrote in message
news:6C**********************************@microsof t.com...
In Java, the Main method cannot have any other access modifier than 'public'. How is it that in C# you can have a private access modifier to the
Main method ? Can anybody throw any light, comparing JVM with CLR ?
Thanks,
Sujala

Nov 15 '05 #2
Ignacio,

Thanks for your answer. But its not true that "in c# the entry point
MUST be declared as static void Main() , if that is not present the
compiler will give you an error." Infact it works even if you declare
the entry point as "private static void Main()" , the compiler gives no
error, neither the CLR throws any run-time error !!! Isnt this strange
??!! Thats precisely the point of confusion. You may try this out.
Thanks,
Sujala

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
Sujala,

public, private, protected and others are access attributes that are
enforced primarily by the compiler (at runtime only when dynamic invocation
is involved). Beyond that, the runtime is free to accept or ignore the
access specifiers - and in the case of Main, it kindly ignores them.

Matters such as these (and this is but one example of many others) are
implementation specific details for the runtime, not for a particular
language.

regards
roy fine
"Sujala" <su*******@hotmail.com> wrote in message
news:6C**********************************@microsof t.com...
In Java, the Main method cannot have any other access modifier than 'public'. How is it that in C# you can have a private access modifier to the
Main method ? Can anybody throw any light, comparing JVM with CLR ?
Thanks,
Sujala

Nov 15 '05 #4

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

Similar topics

3
by: MC D | last post by:
I am trying to move my Main() procedure out of a startup form and into it's own class. I've updated the app settings to use the "Globals" class (which contains the main form). Here's what I have:...
1
by: elexio_byerkes | last post by:
In my application everytime I get an error instead of taking me to the error it displays the error and takes me to static void Main() which is the entry point for my application. For example if...
14
by: Madhav | last post by:
hi all, I was trying the following code on the MS .net compiler: class Item { static int count; public: //static void init() { } Item()
8
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...
15
by: archana | last post by:
Hi all, can anyone tell me differene between public static and private static method. how they are allocated and access?. thanks in advance.
19
by: shana07 | last post by:
Good Day All! I have one problem and wish to consult...... I am using one program -mujava to create mutants. I run the program and comes out this: MyProgram.java class containts 'static void...
1
nomad
by: nomad | last post by:
Hi everyone: This project is driving me crazy and I need some help. I would post it here but I have worked so hard on it that I don't want someone else in my class to steal it. So if I can pm it...
1
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...
5
by: manu verma | last post by:
what is use of public static void main.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.