1. 子类能改变父类的属性值么
能不能贴出代码,说明你想要的结果,继承分好多种的,父类类型也有好多种,属性也分好多种的
package
com.test;
public
class
Test1
{
private
int
t1
=
1;
public
int
getT1()
{
return
t1;
}
public
void
setT1(int
t1)
{
this.t1
=
t1;
}
}
package
com.test;
public
class
Test2
extends
Test1
{
public
static
void
main(String[]
args)
{
Test1
t
=
new
Test2();
t.setT1(3);
System.out.println(t.getClass());
System.out.println(t.getT1());
}
}
控制台:
class
com.test.Test2
3
2. sql 父类下的子类查询的方法,包含父类的信息
-查询各节点的父路径函数(从父到子)
create function f_pid1(@id varchar(3)) returns varchar(100)
as
begin
declare @re_str as varchar(100)
set @re_str = ''
select @re_str = name from tb where id = @id
while exists (select 1 from tb where id = @id and pid is not null)
begin
select @id = b.id , @re_str = b.name + ',' + @re_str from tb a , tb b where a.id = @id and a.pid = b.id
end
return @re_str
end
go
--查询各节点的父路径函数(从子到父)
create function f_pid2(@id varchar(3)) returns varchar(100)
as
begin
declare @re_str as varchar(100)
set @re_str = ''
select @re_str = name from tb where id = @id
while exists (select 1 from tb where id = @id and pid is not null)
begin
select @id = b.id , @re_str = @re_str + ',' + b.name from tb a , tb b where a.id = @id and a.pid = b.id
end
return @re_str
end
go
select * ,
dbo.f_pid1(id) [路径(从父到子)] ,
dbo.f_pid2(id) [路径(从子到父)]
from tb order by id
drop function f_pid1 , f_pid2
drop table tb
/*
id pid name 路径(从父到子) 路径(从子到父)
3. 子类怎样继承父类数据库连接和关闭
SQLConnection1.Params.clear
然后再添上你自己修改的值
SQLConnection1.Params.Values['ServerName'] := '192.168.0.112';
SQLConnection1.Params.Values['Database'] := 'trackData';
SQLConnection1.Params.Values['User_Name'] := 'sa';
SQLConnection1.Params.Values['Password'] := '123456';
SQLConnection1.Open;
4. 修改父类的类型 假设类型为0和1 父类的类型修改为0所有子类的类型也变为0这样sql语句哪位大神写一下下
变成BB了,因为被你强转了。
别听上面的胡扯。。。我是测试了才告诉你答案的。。。铁一样的事实!
A aa=new B();
B bb=(B) aa;
System.out.println(aa.toString());
System.out.println(bb.toString());
这是结果:
com.ejb.example.B@1e5e2c3
com.ejb.example.B@1e5e2c3
这说明aa和bb此时都变成B类了,这是铁一样的事实!换句话说,只要是你强转一个对象,这个对象的类型也就变了。
5. JAVA中子类能修改父类吗
----调用son对象的修改数据方法-----
I am Father:x=100:y=200
I am Son:x=30:y=200
在子类中直接调用x*y=100*200=20000
----调用father对象计算方法-----
修改后用father对象调用x*y=10*20=200
子类不能修改父类的方法,但是可以覆盖,就是子类中参数与名称都与父类相同,在子类中调用时调用子类的方法,若在父类中依旧调用父类中原方法。
6. Java继承后能通过子类创建的对象修改父类里面的属性吗
不可以的,子类无法修改父类里的属性
7. java 子类能改变父类的变量值吗
MultiCalc extends SimpleCalc的意思是子类MultiCalc继承父类SimpleCalc
所以子类继承父类里的变量和方法供子类使用,如果需要子类可以覆盖父类里的变量和方法,当然可以改变父类的变量值那。。。。
如果还有问题就联系我。。。。。。
8. 子类改写了父类的一个属性,其他类调用到了这个父类,那这个属性是改写过的还是没改写的呢Objective C
是Card的空白纸牌,只有子类playingCard的content才是某张扑克牌。
。
9. java子类中如何访问和修改父类成员
根据父类成员的访问权限修饰词分为两种情况:
①父类成员域由private修饰,那么在子类中不能直接访问父类成员域,但是可以通过父类中的公共方法访问以及修改父类成员域。如:
class FatherClass{
private int a;
public int geta(){ return a;}
public void seta(int a){this.a=a;}
}
则在子类中可以通过geta获得父类的成员域的值,通过seta修改父类成员域的值
②父类成员由public或protected或default(不写访问权限修饰词),在子类中可以直接访问父类成员域,可以修改继承的父类成员域,但是不能直接修改父类本身的成员域(可以通过上面所说的public void seta(int a){this.a=a;}对父类本身的成员域进行修改),以下是示例代码:
父类本身的a与子类从父类继承的a占据两个不同的独立的存储空间,在继承之后,他们的值互不相干(继承的时候进行值传递),这样可以避免因为子类中的操作而导致对父类的a的值进行预期结果之外的修改
10. sql 语句中删除父类,子类也一起删除的语句怎么写
举个例子:
表A,是父表,字段有:ID(主键)、名称
表B,是子表,字段有:ID(主键)、名称
把表A的主键设为表B的外键。