Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Uttam KumarRank #1,076 · 1.8K reputationPosted Nov 1, 2022, 11:48 PM EDT
class Program { static void Main() { ClassName objClass = new ClassName(); objClass.Function(); } } class ClassName { // write your code void Function() { Console.WriteLine("ClassName function"); } }Here ClassName is the c# class. And Instantiating in Program class and calling the members of the Class.
I hope this answers your questions.
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Nov 2, 2022, 5:55 AM EDT
A class is a combination of variables and methods. In real world-class refers to a combined unit having different variables and methods in it. For Example: In daily-life “House” is a class, having Television, Refrigerator, etc as variables and Kitchen. Rooms etc as methods.
Declaring a class: We can create a class followed by a class keyword followed by class_name. We have seen a class defined in the following way.
class MyClass { // field, constructor, and // method declarations }Creating Objects: Once a class is defined, you can declare a variable of type class. A Java program creates many objects, thus a program carries out various tasks. Once an object has completed the work, its resources are recycled for use by other objects. A class provides the blueprint for objects, we can create an object from the class. Here the object of the employee class is created.
A class is instantiated using a newkeyword as it invokes the object constructor and allocates memory for a newobject and returns the reference of that memory. The newoperator returns a reference to the object is created. This reference is usually assigned to a variable of the appropriate type. The newoperator is used to create an object of that reference type, where emp is the object reference and Employee() is an object. Once an object is created we will use that object for some manipulation or retrieve data with that object. We may use this object with one of its fields, or call one of its methods to perform any action.