473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Access from inner classes

Howdy!
Given:

public abstract class A {

public abstract int A1(int i);

private class B {
private int B1(int i) {
int j;
...
----------> j = A1(4); // that's what I want
...
}

}

Question: How do I reference the abstract method A1 from
class A inside the method B1 from the inner class B ?

Thanx.

______
Marco
Nov 15 '05 #1
6 2056
Marco <an*******@discussions.microsoft.com> wrote:
Howdy!
Given:

public abstract class A {

public abstract int A1(int i);

private class B {
private int B1(int i) {
int j;
...
----------> j = A1(4); // that's what I want
...
}

}

Question: How do I reference the abstract method A1 from
class A inside the method B1 from the inner class B ?


There are no inner classes in C#, only nested classes - the equivalent
of nested classes marked as "static" in Java. To call A1, you'd need an
instance of A (well, an instance of a subclass of A, in this case). How
you get that is up to you.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Well, here's a new concept for me. What's the point of this generally? I
can see maybe to severely limit the visibility of ClassB even within the
assembly, but is that it?

public class ClassA
{
private class ClassB
{
}
}

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...

There are no inner classes in C#, only nested classes - the equivalent
of nested classes marked as "static" in Java. To call A1, you'd need an
instance of A (well, an instance of a subclass of A, in this case). How
you get that is up to you.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
Well, here's a new concept for me. What's the point of this generally? I
can see maybe to severely limit the visibility of ClassB even within the
assembly, but is that it?

public class ClassA
{
private class ClassB
{
}
}


Basically, yes. If one class is only ever going to be used from within
another, it keeps it nice and tidily away from everything else.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Ok, I meant nested class.
But the point is: To reference a object of a class inside
of itseld I use "this" but for a nested class what should I
use ? "this.this" ???? :-)

______
Marco
Nov 15 '05 #5
Marco <an*******@discussions.microsoft.com> wrote:
Ok, I meant nested class.
But the point is: To reference a object of a class inside
of itseld I use "this" but for a nested class what should I
use ? "this.this" ???? :-)


There *is* no this - there's no implicit instance as there is with an
inner class in Java. You can have an instance of the nested class
without there being *any* instances of the outer class at all.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Here is an exerpt from MSDN article...

Nested classes are useful when an object will logically contain subordinate
objects, but other objects would have use for those objects. An example
might be a Wheel class. This could be a class that clients could create and
use wherever a wheel might be needed in their application. But except in
the most primitive implementations, a wheel is not just a single object,
but is composed of several subordinate objects, each of which build the
wheel. A wheel might have a Rim object, Tire object, Spoke objects and
other objects, without which the wheel could not function. But the average
user would have no need to create a spoke, or a rim, or a bearing — all
he's interested in is the wheel.

In a case like this, it makes sense for the Wheel class to contain the
implementation for all of its subordinate classes. This way, the wheel can
create and manage any contained objects it may need while conveniently
hiding the details of this implementation from the client. Those
subordinate objects the client might reasonably need to have contact with
now and again (for example, a Tire object) can be exposed as part of the
public object model, and those that a client should never see (for example,
a Bearings collection) could be declared private and hidden.
--------------------
From: "Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com>
References: <07****************************@phx.gbl> <MP************************@msnews.microsoft.com >Subject: Re: Access from inner classes
Date: Mon, 10 Nov 2003 09:14:04 -0500
Lines: 25
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <ux**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: 68-74-16-211.ded.ameritech.net 68.74.16.211
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:198029
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Well, here's a new concept for me. What's the point of this generally? I
can see maybe to severely limit the visibility of ClassB even within the
assembly, but is that it?

public class ClassA
{
private class ClassB
{
}
}

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft. com...

There are no inner classes in C#, only nested classes - the equivalent
of nested classes marked as "static" in Java. To call A1, you'd need an
instance of A (well, an instance of a subclass of A, in this case). How
you get that is up to you.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Rakesh, EFT.

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Wolfgang Jeltsch | last post by:
Hello, I want to write a list class with an iterator class as an inner class. The iterator class must have access to certain private members of the list class in order to do its job. Here is a...
9
by: John Harrison | last post by:
Both gcc 3.3.1 and VC++ 7.1 compile the following code. struct Outer { struct Inner { int f() { return c; } }; private: static const int c;
5
by: Fabio Rossi | last post by:
Hi! I'm learning C++ from the book "Thinking in C++". Now I'm reading about nested classes and access control. I have written this code #include <iostream> class Outer { private: int...
4
by: Dennis C. Drumm | last post by:
Is there a way with C# to allow one class access to a method or field of another class, without making that method or field visible to all other classes, as would be the case when making the method...
9
by: MariusI | last post by:
Consider the following class layout public class Order { public ProductOrder AddProductOrder(/* variables required to create a product order */) { /* Check if the product order can be added...
6
by: MilanB | last post by:
Hello //----------------- I have following situation: public class Class1 { public struct Struct1 { public void Function1() {
2
by: dobest03 | last post by:
Hi. Are there any way to access the integer member 'a' of outer structure from inner structure's member function func_inner()? See below the structure... Thanks. struct outer {
5
by: ZikO | last post by:
Hi there. I have a problem. I have created nested classes but don't know how to access to inner classes. I know I can create objects: Hen Object; Hen::Nest ObjectNest; Hen::Nest::Egg...
5
by: emmanuel.rivoire | last post by:
Hello, I spent almost a week to be able to embed Python within my C++ game engine. I wrote a mini-tutorial of what I was able to do so far here :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.