Questions tagged [outer-classes]

49 questions
12
votes
3 answers

Java Inner Class extends Outer Class

There are some cases in Java where an inner class extends an outer class. For example, java.awt.geom.Arc2D.Float is an inner class of java.awt.geom.Arc2D, and also extends Arc2D. (c.f.…
amaidment
  • 6,942
  • 5
  • 52
  • 88
6
votes
2 answers

Getting Reference to Calling Activity from AsyncTask (NOT as an inner class)

Is it at all possible, from within an AsyncTask that is NOT an inner class of the calling Activity class, to get a reference to the instance of Activity that initiated execution of the AsyncTask? I am aware of this thread, however it doesn't exactly…
stormin986
  • 7,672
  • 15
  • 42
  • 54
6
votes
3 answers

Java: Name ambiguity between outer and inner class methods

Suppose I have: public class OuterClass() { public class InnerClass { public void someMethod(int x) { someMethod(x); } } public void someMethod(int x) { System.out.println(x); } } How do I resolve the ambiguity between…
Jake
  • 15,007
  • 22
  • 70
  • 86
5
votes
1 answer

Nested class definition outside outer class's, while outer class contains instance of inner class

C++ How can I put the definition of an inner (nested) class outside its outer (enclosing) class's definition, where the outer class has at least one instance of the inner class as a data member? I searched but the most relevant SO answer I found,…
CodeBricks
  • 1,771
  • 3
  • 17
  • 37
4
votes
2 answers

how to define constructor of a subclass inheriting an inner class?

I am learning inner and outer classes in Java. I know what inner and outer classes are and why they are used. I came across the following question on this topic and could not find an answer. Suppose the following code is given: class outer{ …
Awais Fayyaz
  • 2,275
  • 1
  • 22
  • 45
2
votes
2 answers

How do I copy an instance of a class with a nested class containing a pointer member to the outer class?

Novice C++ programmer here. Let's say I have a class Outer with a nested class Inner. Inner contains a pointer member, set during construction, to Outer. Outer contains a function AddNewInner() that creates a new Inner pointing to itself and adds it…
epezent
  • 23
  • 5
2
votes
3 answers

Read value of outer class from inner class

Public class Main { public static String s; String a="hello"; String b="World"; s=a+b; class Demo{ String m; m=Main.this.s; System.out.println(m); } } Output should be : Hello World I just here …
user3254909
2
votes
1 answer

Invoking methods of a class that instantiated this one

I'm developing a game in Java which uses the Lightweight Java Game Library (LWJGL) with OpenGL. I encountered the following problem. I want to create an ArrayList of all textures in an object in the main loop, and access these from objects…
2
votes
2 answers

Access inner class private vars from outer class

I am trying to access private val inside an inner class, from the outer class without creating an instance of the inner class. Is this even possible to access private inner class values from the outer class ? Thanks in advance.
David Faizulaev
  • 4,651
  • 21
  • 74
  • 124
1
vote
4 answers

How to use Outer Method's input in Anonymous Inner Class?

For Instance how can I use the input 'hasTypedSomeToken' in my Anonymou inner class in the following - public class Login { void display(boolean hasTypedSomeToken) { //some code here Button btnLogIn =…
abhihello123
  • 1,668
  • 1
  • 22
  • 38
1
vote
1 answer

Java multithreading inner class calling outer class

I have an inner class that implement runnable and it makes HTTP requests and then calls the function of outer class to handle the response. The intended behavior is to append all the responses to a List of Objects. Sample code: public class Status…
1
vote
2 answers

C# ASP.net How to access new classes from code behind, not kept in APP_CODE, but kept in same folder as code behind

I want to create classes that are separate files (not code within he aspx.cs) file, and I do not want to put them in the APP_CODE directory. I want the separate class files to reside in the same directory as the main code behind file (aspx.cs). Each…
Mike
  • 11
  • 5
1
vote
1 answer

How to get an outer class instance with an inner class instance in Java

In the book Java concurrency in practice, when talking about ways to publish an object, there is a mechanism is to publish an inner class instance, and it is not safe because inner class instances contain a hidden reference to the enclosing …
liuxl
  • 103
  • 5
1
vote
1 answer

Accessing outer class from within inner class using outerClass.this

The -non-static- inner class has a full accessibility to all regular members of the outer class. but there is another way to access these members using the (outerClass.this.regularMember).., have a look on the following code: public class Car { …
Profess Physics
  • 317
  • 4
  • 11
1
vote
4 answers

Why we can not make an instance of inner class inside the main method of outer class in regular way?

I know how to make an instance of an inner class. But I want to know why we can not do that in the following way: class outerclass{ public static void main(String[] args){ innerclass in=new innerclass(); } class…
Tahseen Adit
  • 184
  • 2
  • 7
  • 22
1
2 3 4