Android Studio - 如何扩展2个类 [英] Android Studio - How to extend 2 Classes

查看:588
本文介绍了Android Studio - 如何扩展2个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我正在尝试扩展两个类,一个是内置的ActionBarActivity,另一个是MainActivityWithButtons.java,我需要扩展第二个类(MainActivity ..),因为我需要访问来自的booleans它。如何继承布尔值?

解决方案

1)你不能扩展两个类,对于这样的函数你应该尝试使用接口并实现它们。每个接口可以为自己扩展一个类。



2)你不能继承布尔值,布尔值是一种类型,原始类型。



相反,您应该尝试实例化并使用布尔变量,或者将其设置为静态并将其称为,



 MainActivity.variable 





因此,引入了多级继承,以便您可以使用2个或更多类的功能。 http://beginnersbook.com/2013/05/java-inheritance-types/ [ ^ ]



  //  我在说什么的例子 
class 首先{
// 头等舱的成员和职能
}

class 第二个 extends 首先{
// 第一和第二类的成员和功能
}

class 第三个延伸第二个{
// 成员和功能第一,第二和第三课
}





你可以使用第三并且调用函数和成员继承自 First Second 类。 甚至布尔


Hey guys, I'm trying to extend two classes, the one is the built in ActionBarActivity and the other is MainActivityWithButtons.java , I need to extend the second one (MainActivity..) because I need to access the booleans from it. How do I inherit the booleans?

解决方案

1) You cannot extend two classes, for such function you should try using interfaces and implement them. Each interface can in turn extend one class for itself.

2) You cannot inherit booleans, boolean is a type, primitive type.

Instead, you should try instantiating and using the boolean variable, or make it static and call it as,

MainActivity.variable



For this reason, multilevel inheritance has been introduced so that you can use features of 2 or more classes. http://beginnersbook.com/2013/05/java-inheritance-types/[^]

// Example of "what I am saying"
class First {
   // members and functions of First class
}

class Second extends First {
   // members and functions of First and Second class
}

class Third extends Second {
   // members and functions of First, Second and Third class
}



You can use Third and call functions and members inherited from First and Second class also. Even boolean.


这篇关于Android Studio - 如何扩展2个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆