instance

How to define an instance?

一笑奈何 提交于 2019-12-01 12:26:31
I was asked a question in an interview and i wasn't able to answer it... Here is the question How will you define an instance[c#]? My answer was it is an other name of an object ... what is the right answer for this question... Instance is to class as cake is to recipe. Any time you use a constructor to create an object, you are creating an instance. MyObject obj = new MyObject( ); I would describe instance as a single copy of an object. There might be one, there might be thousands, but an instance is a specific copy, to which you can have a reference. Class is the blueprint, instance is the

JavaFx: how to reference main Controller class instance from CustomComponentController class?

主宰稳场 提交于 2019-12-01 10:52:21
问题 WHAT I HAVE is a standard JavaFX application: Main.java, MainController.java & main.fxml . To add custom component, I created CustomComponentController.java and custom_component_controller.fxml . PROBLEM is that in CustomComponentController methods I need to reference other methods and standard components from MenuController . I add public static MainController mc; to MainController class body, so that it can be seen from CustomComponentController ( MainController.mc.neededMethod() ). Then I

How would I create a new object from a class using a for loop in java?

橙三吉。 提交于 2019-12-01 10:11:37
问题 I have a class named Card and I have this for loop: int i; for (i = 0; i < 13; i++) { Card cardNameHere = new Card(); } What I want to do is create new instances based on the for loop. So for example, I would like the names to be card1, card2, card3, etc. The number would come from the for loop. I have tried this and it does not seem to work: int i; for (i = 0; i < 13; i++) { Card card[i] = new Card(); } Can anyone tell me what I am doing wrong? Thanks. So I am using the solution from

Integrating native JavaScript classes in an Angular app

扶醉桌前 提交于 2019-12-01 09:52:00
问题 I have a native JavaScript class: var Holder = new function(elements) { this.elements = elements; this.anyFunction() { // use of this.elements }; }; How to use it in an Angular-way? For example, if I would like to use: .controller('AnyController', ['Holder', function (Holder) { var elements = [ {id: 1, label: 'foo'}, {id: 2, label: 'bar'} ]; $scope.holder = new Holder(elements); }]) How should I register my Holder class then? What are the options (if any)? In parallel, is it that bad to use

Python: Call method by instance object: “missing 1 required positional argument: 'self'” [duplicate]

倖福魔咒の 提交于 2019-12-01 06:41:58
This question already has an answer here: TypeError: attack() missing 1 required positional argument: 'self' 2 answers I'm new to Python. I've written two Classes, the second one has an instance of the first one as a member variable. Now I want to call a method of Class2 via the instance of it in class one. I could not find an answer for it. Something like this: class Class1: def uselessmethod(self): pass class Class2: def __init__(self): self.c = Class1() def call_uselessmethod(self): self.c.uselessmethod() k = Class2 k.call_uselessmethod() # Error! Gives the following error: k.call

Create class instance from string

泪湿孤枕 提交于 2019-12-01 06:28:59
I have a C# method which creates a new instance of a class from a string, however, I get an error when running the code. obj = (ClassX)Activator.CreateInstance(Type.GetType("classPrefix_" + className)); ArgumentNullException was unhandled Value cannot be null Parameter name: type Any help on this error would be appreciated. You may need to use the assembly qualified name as the argument to Type.GetType eg AssemblyName.Namespace.ClassName MSDN Doc on assembly qualified names You may just be missing the namespace from the classname Works for me: class ClassX {} class classPrefix_x : ClassX {}

Python: Call method by instance object: “missing 1 required positional argument: 'self'” [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-01 04:51:49
问题 This question already has answers here : TypeError: attack() missing 1 required positional argument: 'self' (2 answers) Closed last year . I'm new to Python. I've written two Classes, the second one has an instance of the first one as a member variable. Now I want to call a method of Class2 via the instance of it in class one. I could not find an answer for it. Something like this: class Class1: def uselessmethod(self): pass class Class2: def __init__(self): self.c = Class1() def call

Create class instance from string

混江龙づ霸主 提交于 2019-12-01 04:23:07
问题 I have a C# method which creates a new instance of a class from a string, however, I get an error when running the code. obj = (ClassX)Activator.CreateInstance(Type.GetType("classPrefix_" + className)); ArgumentNullException was unhandled Value cannot be null Parameter name: type Any help on this error would be appreciated. 回答1: You may need to use the assembly qualified name as the argument to Type.GetType eg AssemblyName.Namespace.ClassName MSDN Doc on assembly qualified names 回答2: You may

Obtaining reference to Class instance by string name - VB.NET

十年热恋 提交于 2019-12-01 02:51:15
问题 Is it possible using Reflection or some other method to obtain a reference to a specific class instance from the name of that class instance? For example the framework for the applications i develop heavily uses public class instances such as: Public bMyreference as MyReference = new MyReference Then throughout the application bMyReference is used by custom controls and code. One of the properties of the custom controls is the "FieldName" which references a Property in these class instances

Example of Class with User Input [closed]

谁都会走 提交于 2019-12-01 02:38:34
In most of the examples I have seen online while (trying to) learn classes, the instances of the classes are defined by the programmer. Are there any ways of creating an instance of a class where it the variable that stores the class is defined by the user? This is an example of an object from another SO question: class StackOverflowUser: def __init__(self, name, userid, rep): self.name = name self.userid = userid self.rep = rep dave = StackOverflowUser("Dave Webb",3171,500) How can this be changed so that the user can create instances based off of the class? jonrsharpe There are broadly two