Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are the main differences between a Java/C# static class?

In C# a static class is a class that, in addition to not supporting inheritance, can have any kind of type member a "normal" class can have except instance members.

Not so sure how static classes work in java, but based on the limited amount of java code I have seen, it's clear to me that they don't work quite the same way.

Can someone please enumerate the differences?

like image 553
John Smith Avatar asked Jan 30 '13 03:01

John Smith


People also ask

What are three features that distinguish Java from a language like C?

KEY DIFFERENCES:C is a Procedural Programming Language whereas Java is an Object-Oriented language. C is middle level language while Java is high level language. C does not support threading on the other hand Java has a feature of threading. C supports pointers but Java does not support pointers.

Which is easier C or Java?

Generally, we can consider C is easier than Java, as C being structural and Java being object oriented programming language, the later has more features and can make it tougher when compared to C.


1 Answers

Static classes in Java are one of three kinds of nested classes provided by the language (the other two being non-static nested classes and function-scoped classes).

Static classes of Java behave the same way that nested classes of C#: they have access to static members of the enclosing class, but cannot access instance members without an additional reference to the enclosing object. In contrast, non-static nested functions can access instance variables, but you need an enclosing instance in order to be instantiated.

like image 66
Sergey Kalinichenko Avatar answered Oct 14 '22 04:10

Sergey Kalinichenko