0% found this document useful (0 votes)
3 views11 pages

Entry Points in Java and C Programs

The document compares how C, C++, Java, and C# handle the main entry point for a program and class definitions. In C, the main function is defined outside of any class. In C++, code must be within a class but main is still outside. Java requires all code to be within a class, so it introduced the static keyword to allow main to be called without an object. C# also defines main as static to follow Java's approach while keeping all code within classes.

Uploaded by

Suman Pravallika
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Entry Points in Java and C Programs

The document compares how C, C++, Java, and C# handle the main entry point for a program and class definitions. In C, the main function is defined outside of any class. In C++, code must be within a class but main is still outside. Java requires all code to be within a class, so it introduced the static keyword to allow main to be called without an object. C# also defines main as static to follow Java's approach while keeping all code within classes.

Uploaded by

Suman Pravallika
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

C Program

-Collection of Members void main() <- entry point { -Call the members from here for execution }

In a Object Oriented Programming Language the Code is enclosed under a Container known as Class

CPP Program class Example { Collection of Members }; void main() <- entry point { -Create the object of class -Using the object invoke members of class }

-A Class is a User-defined Data type -To use it first create a copy of it

-Copy of a Class is known as object

-As per object oriented programming every line of code has to be under a Class only.
-In CPP Language the Main Function is defined out of the Class.

-Because anything under a Class has to be accessed only using the object of the Class, which gets created under the Main Function only.

-When Java Language was introduced it was designed in such a way that not even a single line of code can be present out of the Class. -To overcome the problem with Main it has introduced a concept known as Static.

-If a method is defined as Static object of the Class is not required to invoke it. -Main Method in Java Class will be defined as Static from where the execution starts.

Java Program class Example { Collection of Members static void Main() <- entry point { -Create the object of class -Using the object invoke members of class } }

C# was designed basing on the principals of Java so in case of Main it followed the guidelines laid by Java so it also defines Main as Static

C#.Net Program class Example { Collection of Members static void Main() <- entry point { -Create the object of class -Using the object invoke members of class } }

You might also like