class init & object creation in inheritance
example:
execute SelfBall.java 's main() function,then get the result.
GrandpaBall.java
/**
* grandpa ball
* @author eric
* @date 2010-3-19 上午11:43:42
*/
public class GrandpaBall {
// static fields
protected static int gx = gxInit();
protected static int gy;
// non-static fields
protected int ga = gaInit();
// static block
static {
System.out.println("grandpa static block init.");
}
// non-static block
{
System.out.println("grandpa non-static block init.");
}
// constructor
public GrandpaBall() {
System.out.println("grandpa constructor execute.");
}
private static int gxInit() {
System.out.println("grandpa static field init.");
return 1;
}
private int gaInit() {
System.out.println("grandpa non-static field init.");
return 1;
}
}
FatherBall.java
/**
* father ball
* @author eric
* @date 2010-3-19 上午11:44:01
*/
public class FatherBall extends GrandpaBall {
// static fields
protected static int fx = fxInit();
protected static int fy;
// non-static fields
protected int fa = faInit();
// static block
static {
System.out.println("father static block init.");
}
// non-static block
{
System.out.println("father non-static block init.");
}
// constructor
public FatherBall() {
System.out.println("father constructor execute.");
}
private static int fxInit() {
System.out.println("father static field init.");
return 2;
}
private int faInit() {
System.out.println("father non-static field init.");
return 2;
}
}
SelfBall.java
/**
* self ball,test class init & object creation
* @author eric
* @date 2010-3-19 上午11:44:19
*/
public class SelfBall extends FatherBall {
// static fields
protected static int sx = sxInit();
protected static int sy;
// non-static fields
protected int sa = saInit();
// static block
static {
System.out.println("self static block init.");
}
// non-static block
{
System.out.println("self non-static block init.");
}
// constructor
public SelfBall() {
System.out.println("self constructor execute.");
}
private static int sxInit() {
System.out.println("self static field init.");
return 3;
}
private int saInit() {
System.out.println("self non-static field init.");
return 3;
}
// main
public static void main(String[] args) {
System.out.println();
System.out.println("executeing main() ... class has been loaded.");
System.out.println("object is going to be created:");
System.out.println();
// create object
SelfBall sb1 = new SelfBall();
System.out.println();
System.out.println("object created.");
}
}
分享到:
相关推荐
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class> <init-param> <param-name>services.configuration.file</param-name> <param-value>/WEB-INF/flex/services-config.xml</param-value> ...
log.error("Class loader creation threw exception", t); System.exit(1); } } private ClassLoader createClassLoader(String name, ClassLoader parent) throws Exception { //CatalinaProperties解析$...
- **Object Creation**: Objects are created using allocators like `alloc` and `new`. For example, `[MyClass alloc]` allocates memory for a new instance of `MyClass`. - **Initialization**: After ...
<bean id="C3PONativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" lazy-init="true"/> ``` 这里的关键在于配置了`lobHandler` Bean来处理CLOB和BLOB类型的字段。...
本文为大家分享了Python实现批量压缩图片的具体代码,供大家参考,具体内容如下 # -*- coding: utf-8 -*- ...class Compress_Picture(object): def __init__(self): # 图片格式,可以换成.bpm等
The _class_init() function The _init() function And the rest... Creating a widget from scratch Introduction Displaying a widget on the screen The origins of the Dial Widget The Basics gtk_dial_realize...
PEP 487: Simpler customization of class creation PEP 487: Descriptor Protocol Enhancements PEP 519: Adding a file system path protocol PEP 495: Local Time Disambiguation PEP 529: Change Windows ...
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { // Delegate methods func imagePickerController(_ picker: UIImagePickerController, ...
- **Configuration Information**: Servlets can obtain configuration information using the `ServletConfig` object, which is passed to the `init()` method during initialization. - **`ServletContext` ...
.\Objects\xxxx.axf: Error: L6248E: xxxx.o(.constdata) in PI region ‘text’ cannot have address type relocation to OBJECT_CLASS1_TABLE in PI region ‘text’. .\Objects\xxx.axf: Warning: L6039W: ...
class, optional commit support on Bochs exit, save/restore file attributes, 1.44 MB floppy support, set file modification date/time - converted the complete hdimage stuff to the new 'hdimage' ...