Questions tagged [instance]

In object-oriented programming an instance is an occurrence or a copy of an object, whether currently executing or not.

Instances of a class share the same set of attributes, yet will typically differ in what those attributes contain. For example, a class "Employee" would describe the attributes common to all instances of the Employee class. For the purposes of the task being solved Employee objects may be generally alike, but vary in such attributes as "name" and "salary".

Related tags:

5388 questions
23
votes
4 answers

"No enclosing instance of type" error while calling method from another class in Android

Colleagues, I have the such question: 1. In my first class I have the public class parseYouTubeAndYahoo extends AsyncTask> to parse data from internet. But I need to call execute() method of this class from…
Eugene Shmorgun
  • 2,083
  • 12
  • 42
  • 67
23
votes
1 answer

Integer caching in Java with new operator

In the below class I have tried to compare the wrapper class with the primitive but the results are different. I have checked the following links links: The more interesting question is why new Object(); should be required to create a unique…
User12345
  • 486
  • 1
  • 3
  • 18
23
votes
2 answers

How to instantiate an object in TypeScript by specifying each property and its value?

Here's a snippet in which I instantiate a new content object in my service: const newContent = new Content( result.obj.name result.obj.user.firstName, result.obj._id, result.obj.user._id, ); The problem is that this way of…
YSA
  • 799
  • 1
  • 12
  • 30
23
votes
4 answers

VB.NET: Get class name of a instance

Is there a way to get the instance's class name with VB.NET?
afe
  • 241
  • 1
  • 2
  • 3
23
votes
4 answers

Getting the instance that called the method in C#

I am looking for an algorithm that can get the object that called the method, within that method. For instance: public class Class1 { public void Method () { //the question object a = ...;//the object that called the method (in…
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
23
votes
2 answers

method objects vs function objects , Python class instances vs class

I am trying to verify the difference between instance attributes and class attributes as laid out by the Python tutorial release 2.7.3 dated Nov 01, 2012, chapter 9: Classes, Page 66 last line (source): Valid method names of an instance object…
Ankur Agarwal
  • 23,692
  • 41
  • 137
  • 208
23
votes
3 answers

Amazon EC2 terminated instance (Free Tier)

I am using free tier on Amazon. I had one micro instance, which I terminated. If I create another one (micro) instance, will Amazon start charging me? I can still see my terminated instance in the instances list, but I cannot start or reboot it.…
Loadeed
  • 557
  • 2
  • 8
  • 18
22
votes
2 answers

Swift: Creating an Array with a Default Value of distinct object instances

I noticed a bit weird (and dangerous IMHO) behavoir in Creating an Array with a Default Value. As stated in Swift 2.1: Collection Types Swift’s Array type also provides an initializer for creating an array of a certain size with all of its values…
Franco Rondini
  • 10,841
  • 8
  • 51
  • 77
22
votes
2 answers

Python: asking if two objects are the same class

I have a class Animal and other animals inherit from it (e.q. Sheep, Wolf).I want to check if two objects are the same class and if so, it should create new object of the same class and if they are not, they are fighting. if x and y same object: …
Cardano
  • 452
  • 2
  • 8
  • 16
21
votes
4 answers

Is calling static methods via an object "bad form"? Why?

In a recent question, someone asked about static methods and one of the answers stated that you generally call them with something like: MyClassName.myStaticMethod(); The comments on that also stated that you could also call it via an object…
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
21
votes
4 answers

Android: How to ignore or disable savedInstanceState?

I want to ignore or disable savedInstanceState so that the state of current activity won't save when I go to the next activity. public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
Kris
  • 3,709
  • 15
  • 50
  • 66
21
votes
4 answers

What is the correct ways to write Boto3 filters to use customise tag name?

I am trying to list the instances on tag values of different tag keys For eg> one tag key - Environment, other tag key - Role. My code is given below : import argparse import boto3 AWS_ACCESS_KEY_ID = '' AWS_SECRET_ACCESS_KEY =…
Abhi
  • 213
  • 1
  • 2
  • 5
21
votes
5 answers

No such instance field

I'm trying to get my application to save some data when the orientation of the screen is changed using the onSaveInstanceState to save a boolean value mCheated. I've set numerous break points and am getting an error for the mCheated boolean value…
algorhythm
  • 3,304
  • 6
  • 36
  • 56
21
votes
5 answers

When to use static variables/methods and when to use instance variables/methods in Java?

i would like to ask the question when it would be advantageous to use static variables/methods or in the other case instance variables/methods in Java? I know that it depends on the certain case (like programming util-classes as static methods),…
user3133542
  • 1,695
  • 4
  • 21
  • 42
21
votes
6 answers

no suitable constructor exists to convert from "test *" to "test", constructor,

I'm new to c++ and I'm having difficulties with constructor and classes. So, here is my header file: #pragma once #include using namespace std; class test { private: string name; int number; public: test(); …
klo
  • 414
  • 2
  • 6
  • 14