初学者 - 基本继承问题 - 公共/受保护 [英] Beginner - basic inheritance problem -- public/protected
问题描述
我是oop的新手所以请耐心等待:
有人可以向我解释为什么protected void
runCategory()方法 ;无法访问在createNav()方法中轻松访问的本地ddlCategory对象
?我认为,因为
它们属于同一个类,所以ddlCategory对象将是这个类中所有方法都可以访问的。$
以下是代码片段:
public partial class Main:System.Web.UI.Page
{
public void Page_Load(object sender,EventArgs e)
{
createNav();
}
public void createNav();
{
//网页导航代码 - 两个下拉列表,
ddlCategory和ddlSculpture
}
protected void runCategory();
{
// ddlCategory选择的定义
}
protected void runSculpture();
{
// ddlSculpture选择的定义
{
谢谢!
I am new to oop so please bear with me:
Could someone please explain to me why the "protected void
runCategory() method" cannot access the local ddlCategory object that
is easily accessed in the "createNav() method"? I thought that because
they are in the same class, that the ddlCategory object would be
accessible to all methods in this class.
Here is the code snippet:
public partial class Main: System.Web.UI.Page
{
public void Page_Load(object sender, EventArgs e)
{
createNav();
}
public void createNav();
{
//code for navigation for web pages -- two dropdownlists,
ddlCategory and ddlSculpture
}
protected void runCategory();
{
//definition for ddlCategory selection
}
protected void runSculpture();
{
//definition for ddlSculpture selection
{
Thanks!
推荐答案
你得到什么错误?
发布编译器和文章的确切消息发生的代码是
。
-
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局
Ranginald <哒******* @ gmail.com>在消息中写道
news:11 ********************* @ e56g2000cwe.googlegro ups.com ...
Hi,
What error are you getting?
Post the exact message from the compiler and also the piece of code where it
occur.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ranginald" <da*******@gmail.com> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com...
我是oop的新手所以请耐心等待:
有人可以向我解释为什么protected void
runCategory()方法无法访问在createNav()方法中可以轻松访问的本地ddlCategory对象?我认为因为
它们属于同一个类,所以ddlCategory对象可以被这个类中的所有方法访问。
这是代码片段:
public partial class Main:System.Web.UI.Page
{public void Page_Load(object sender,EventArgs e)
{
createNav();
}
public void createNav();
{
//网页导航代码 - 两个下拉列表,
ddlCategory和ddlSculpture
}
protected void runCategory();
{// ddlCategory选择的定义
}
protected void runSculpture();
//
for ddlSculpture selection
$
谢谢!
I am new to oop so please bear with me:
Could someone please explain to me why the "protected void
runCategory() method" cannot access the local ddlCategory object that
is easily accessed in the "createNav() method"? I thought that because
they are in the same class, that the ddlCategory object would be
accessible to all methods in this class.
Here is the code snippet:
public partial class Main: System.Web.UI.Page
{
public void Page_Load(object sender, EventArgs e)
{
createNav();
}
public void createNav();
{
//code for navigation for web pages -- two dropdownlists,
ddlCategory and ddlSculpture
}
protected void runCategory();
{
//definition for ddlCategory selection
}
protected void runSculpture();
{
//definition for ddlSculpture selection
{
Thanks!
" Ranginald" <哒******* @ gmail.com> écritdansle message de news:
11 *********************@e56g2000cwe.googlegroups.c om ...
| public void createNav();
| {
| //网页导航代码 - 两个下拉列表,
| ddlCategory和ddlSculpture
| }
我的猜测是你在
createNav()方法中声明了ddlCategory和ddlSculpture,而不是在类的主体中声明私有字段。 />
Joanna
-
Joanna Carter [TeamB]
顾问软件工程师
"Ranginald" <da*******@gmail.com> a écrit dans le message de news:
11*********************@e56g2000cwe.googlegroups.c om...
| public void createNav();
| {
| //code for navigation for web pages -- two dropdownlists,
| ddlCategory and ddlSculpture
| }
My guess is that you are declaring ddlCategory and ddlSculpture in the
createNav() method instead of private fields in the body of the class.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
" Ranginald" <哒******* @ gmail.com> écritdansle message de news:
11 *********************@e56g2000cwe.googlegroups.c om ...
| public void createNav();
| {
| //网页导航代码 - 两个下拉列表,
| ddlCategory和ddlSculpture
| }
我的猜测是你在
createNav()方法中声明了ddlCategory和ddlSculpture,而不是在类的主体中声明私有字段。 />
Joanna
-
Joanna Carter [TeamB]
顾问软件工程师
"Ranginald" <da*******@gmail.com> a écrit dans le message de news:
11*********************@e56g2000cwe.googlegroups.c om...
| public void createNav();
| {
| //code for navigation for web pages -- two dropdownlists,
| ddlCategory and ddlSculpture
| }
My guess is that you are declaring ddlCategory and ddlSculpture in the
createNav() method instead of private fields in the body of the class.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
这篇关于初学者 - 基本继承问题 - 公共/受保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!