47
Reply

What is the advantage of static class over class ?

Ujjval Shukla

Ujjval Shukla

8y
14.6k
3
Reply

    In simple way we van say for accessing static class don't need to create instance and for normal class need to create instance

    http://www.codeproject.com/Articles/891433/Must-Remember-Key-Concepts-to-Keyword-StaticAbove URL solves almost all queries related to static.

    Static class members not a change values in using child class method and fiction. Static class does not allow user to create instances of the class. as well as it restrict the user to inherit any data members/functions to derived class. So, imagine a situation where we dont want a user to create instance of class or dont want user to inherit it to child class.and this class data not use child class inherit but data members/functions in child class and not a changes of a data in using child class

    by using static class we dont need to create object of that class. we can easily access method of that class. genrally we used static class to write helper methods

    The following list provides the main features of a static class:Contains only static members.Cannot be instantiated.Is sealed.Cannot contain Instance Constructors.

    No need to create object to access meber of static class.

    In simple way we van say for accessing static class don't need to create instance and for normal class need to create instance

    In simple way we van say for accessing static class don't need to create instance and for normal class need to create instance

    static class does not require any object to call any function or attribute

    A static class can make your implementation simpler and faster because you do not have to create an object in order to invoke its methods. It is useful to organize the methods inside the class in a meaningful way, such as the methods of the Math class in the System namespace.

    Static class does not allow user to create instances of the class as well as it restrict the user to inherit any data members/functions to derived class. So, imagine a situation where we dont want a user to create instance of class or dont want user to inherit it to child class. one should go with Static class.

    No need of creating instance for static class is the major advantage.

    Compiler ensure that no one can create object of static class. Static class are fast in comparison of simple class because no object needed. Static class behave like sealed classes no one can inherit the.Fore more properties you can visthttps://interview-preparation-for-you.blogspot.in/2011/09/static-class.html

    static classes are meant to provide common functionalities and properties. The main advantage is that we need not to create any object in order to access these. All the members under it works like global for all the other classes.

    I don't see a reason that we should try to see advantages of Static Class over Instance Class. They are two different things that their members can be accessed with or without an instance of a class. Just because you don't need an instance, it doesn't mean it's an advantage. If I need to know the possible ways from one source to another destination then there are multiple possibilities then it makes sense to have Instance Class to store all the routes. And if I am just returning the addition of two numbers then I don't need an instance to store a result. e.g Math class in .NET Framework.

    A static class doesn't require a instance as like normal class for accessing class members.

    static class runs automaticall by just accessing with class name , and normal class need to initialized by object

    If your class doesn't store any state, then use a Static class.If it stores state and you require a single instance, then (maybe) use a Singleton.Otherwise use a regular class

    If your class doesn't store any state, then use a Static class.If it stores state and you require a single instance, then (maybe) use a Singleton.Otherwise use a regular class

    Static class is a pre compiled class so it can access directly without compiling run time.

    If you are using Static class then no need to Create Class instance. and one more thing Static class only take Static Method Ex- using System; public static class staticclass {public static void show(){Console.WriteLine("Hello");}static void Main(){staticclass.show();} }

    If you are using Static class then no need to Create Class instance. and one more thing Static class only take Static Method Ex- using System; public static class staticclass {public static void show(){Console.WriteLine("Hello");}static void Main(){staticclass.show();} }

    In the main method we can directly access the static members because main method is also a static method where as we have to create instance to consume the member of instance class.

    Static class can contain only static member in it, So there is no need to create the instance of the static class to consume the members.

    in case of static class you dont need to create an instance

    when we want to access members of class without creating objects, static class may be used. The advantage of static class over class is that in static class members can be directly access by classname.membername but in class we need to create instances for accessing members of class.

    We don't need to create Objects we can directly call static class methods you can use extension methods.We can use it if you are using the classes frequently.

    The best approach is to rephrase the question to: when to use static class or concrete class. The answer is it depends on the application. For example a hammer does not have an advantage over a screwdriver. It depends on the work.Look at the application from an OOP perspective. Look up the characteristics of classes on the Microsoft developers site. Then ask yourself how your software will represent the information. Is the information unique? What is the scope? Performance concerns? Organization of methods? Best wishes

    The best approach is to rephrase the question to: when to use static class or concrete class. The answer is it depends on the application. For example a hammer does not have an advantage over a screwdriver. It depends on the work.Look at the application from an OOP perspective. Look up the characteristics of classes on the Microsoft developers site. Then ask yourself how your software will represent the information. Is the information unique? What is the scope? Performance concerns? Organization of methods? Best wishes

    1) If you are using a static class , you do not need to create instance for accessing it's properties and methods. 2) Basically static classes are used to make Utility methods (Utils).

    Static members are managed by CLR

    In the simple way can say that no need to create instance in static class and it is mandatory in class.

    static classes can'nt be instantiated bcoz static calsses is a sealed class we can'nt create the object by using create the object only instatnce variables

    static class can'nt be instatntiated bcoz static classes are sealed class we can'nt create the object by using create the object only instance variables

    In simple way we van say for accessing static class don't need to create instance and for normal class need to create instance

    Static Class is no object of static class can be created and must contain only static members

    Static Classes have only one object life,Hence we cannot create multiple objects of static classes but normal classes can be instantiated for creating many objects of the same class We use Static classes in scenarios in like creating a utilities class, implementing a singleton pattern etc.

    Static classes are used for 1) Data Caching: e.g- List of Country or States 2) Utility Classes: e.g.- You can create Utility classes as static as there is no need of creating object of these classes. 3) You Can Access methods / variables of Static class without creating object of the class. 4) These Classes are loaded when application is loaded in memory.

    Static classes are used for 1) Data Caching: e.g- List of Country or States 2) Utility Classes: e.g.- You can create Utility classes as static as there is no need of creating object of these classes. 3) You Can Access methods / variables of Static class without creating object of the class. 4) These Classes are loaded when application is loaded in memory.

    When all members/porperties in a class are static then use declare a class as static When you wnat to maintain the unique value for a varible for multiple threads then use Static

    Static class is a class with only one instance.Used for building utility codes and singleton architecture.

    By declaring a method using the static keyword, you can call it without first creating an object because it becomes a class method that belongs to a class rather than an object.

    static classes are used when a class provides functionality which is not specific to any instance. If you want an object to be shared between multiple instances you will use a static class. they can not be instantiated , it can not be inherited, it can have only static members it can have only static constructor.

    Class : To access any members of the class we need to take the help of the instance. Static Class : No need to create instance. Directly with the help of class name we can access the members.

    Static class does not allow user to create instances of the class as well as it restrict the user to inherit any data members/functions to derived class. So A static class can make your implementation simpler ,safe and faster because you do not have to create an object in order to invoke its methods.

    A static class can make your implementation simpler and faster because you do not have to create an object in order to invoke its methods. It is useful to organize the methods inside the class in a meaningful way, such as the methods of the Math class in the System namespace.

    1.)When we have a normal class and its methods being used very frequently in a given app, then it would speed up things if we made this class a static class with static methods. This is because there is always a cost incurred in terms of resource usage ( CPU, memory, time) EVERY TIME a normal class is instantiated, whereas for static class its only a ONE-TIME cost when static constructor is FIRST called.2.)The main advantage of Static Classes come when there is a need to use WebMethod or a webservice, so that the application can call the static method without creating an object.http://www.geekinterview.com/question_details/89408http://www.geekinterview.com/talk/15090-why-we-create-static-class-c.html