JavaBeans & no-arg-constructor

Hi,
I'm new to JavaBeans and while reading the JavaBeans API Specification (Version 1.01, as I couldn't find a newer version), I was faced with the question:
Why doesn't the definition of a bean in this specification contain the fact that a bean must have a public no-arg constructor?
Every bean I've yet seen did contain a no-arg constructor and everybody says they had to do so. But could anyone please point me to the section in the specification (http://www.java.sun.com/products/javabeans/docs/spec.html) from which this fact logically follows? Maybe I just didn't recognize it when reading, maybe it just follows implicitly...
Perhaps somebody also knows if there will be a new version of the spec. For example, the current version says: "All beans must support either Serialization or Externalization" though long term storage was introduced in JDK v1.4. Where can I find a draft for such a new spec if there is any?
Thanx

You're quite right, but you'll have to admit that the section you quoted is just a possible scenario (at the beginnig of chapter 3, the spec says Note that this section is intended to be illustrative rather than prescriptive).
I'm still wondering if a class that looks like a bean but has no default constructor either is not a bean or is a bean, but not supported by current JDKs.
In fact, the XML bean persistence allows you to make objects persistent which don't support a default constructor (i.e. they might just provide a factory method). And the method Beans.getInstanceOf(Object, Class) could (in future releases) make it possible to take an Object containing all initialization info as it's first argument and then initialize a new "bean" without using a default constructor.
Of course, if we could call such a "bean" without no-arg-constructor really a bean, this wouldn't change much as we couldn't use it in our today 's builder tools. But wouldn't it be nice some day to have beans with some non-mutable properties that you can just specify at the creation point of such a bean?
Please let me know your opinion!
Stefan

Similar Messages

  • Cmp-field of type 'java.lang.Long' does not have a no-arg constructor

    Hi,
    I am a newer of Oracle9i JDeveloper and I am learning it by "Oracle9i JDeveloper Reviewers Guide". I did the sample as the guideline in "Oracle9i JDeveloper Reviewers Guide". But when I tried to run the sample I made, the error : "cmp-field of type 'java.lang.Long' does not have a no-arg constructor which is needed for properties/fields based mapping" was appeared.
    Any one know how to correct it?
    Thanks in advance.
    Best Regards,
    Double
    Auto-deploying file:/E:/JDev9i/jdev/Workspace2/J2EE/classes/ (No previous deployment found)...
    Error compiling E:\JDev9i\jdev\Workspace2\J2EE\classes: cmp-field of type 'java.lang.Long' does not have a no-arg constructor which is needed for properties/fields based mapping
    Oracle9iAS (9.0.3.0.0) Containers for J2EE initialized

    I'm getting the same thing. The message doesn't indicate which of the four beans I have that use type Long is encountering this. I suspect that since it says 'constructor' it is one of the two which uses an Long for a primary key.
    Yet another OC4J bug,
    Michael A. Moran

  • FlatGroup does not have a no arg constructor

    Hi All,
    I am using weblogic 6.0 sp1, wrote a custom realm that contains
    a class
    public class CustomGroup extends FlatGroup implements Serializable
    I have a method,
    CustomGroup getGroup(String groupId){....}
    When the method returns an object of type CustomGroup to the client,
    I get the following error,
    ERROR:java.rmi.UnmarshalException: failed to unmarshal class admin.rdbmsrealm.CustomGroup;
    nested exception is:
         * java.io.InvalidClassException: weblogic.security.acl.FlatGroup,
    Missing no-arg constructor for class
    Do I HAVE to extend from Flatgroup to implement a group in the
    custom realm ?? And does Weblogic always use the Caching realm
    to access the RDBMSRealm ??
    Thanks in advance,
    SKolli

    I'm getting the same thing. The message doesn't indicate which of the four beans I have that use type Long is encountering this. I suspect that since it says 'constructor' it is one of the two which uses an Long for a primary key.
    Yet another OC4J bug,
    Michael A. Moran

  • No-arg constructor for Serializable

    Hello all!
    Is it REQUIRED for an object that implements java.io.Serializable to have a no-argument constructor? Because I've read some that it is and some its not.
    What is the use of having a no-argument constructor?
    Thanks in advance!

    http://java.sun.com/j2se/1.4.1/docs/api/java/io/Serializable.html
    As you can see from the API docs, a non-serializable superclass of a serializable class must have a no-arg constructor. This is because the superclass state is not serialized (except where done manually in the subclass), and so the constructor is used to safely initialise the superclass. A class that implements Serializable is not required to have a no-arg constructor.
    Thus you will get a runtime error if you try to serialize a class that implements Serializable, but whose direct superclass does not implement Serializable and does not have a no-arg constructor.

  • No-arg constructor for SQJL iterator class

    I'm to use SQLJ with EJB:
    I used SQLJ to define a public DeptRecs:
    #sql public iterator DeptRecs implements java.io.Serializable
    ( int deptNo, String dName, String loc );
    I wish to pass the iterator out of EJB:
    DeptRecs departments = deptEJB.getDepartments();
    As EJB communication is based on object serialization /
    deserialization, it is critical to provide a no-arg constructor
    for all the classes passed. But the SQLJ iterator has only one
    constructor:
    public DeptRecs(sqlj.runtime.profile.RTResultSet resultSet)
    How can I have a no-arg constructor for the iterator class?
    Or if this is a wrong way to have SQLJ work with EJB, could
    anybody tip me the correct structure?

    You may want to look at the following SQLJ demo file:
    sqlj/demo/SubclassIterDemo.sqlj
    This demonstrates the following:
    - a class Emp to hold the values of the rows
    - a subclass EmpColl of the iterator to read the rows into Emp
    objects.
    The EmpColl class has a getEmpVector() method that returns a Java
    vector with Emp objects as elements. Such a vector would be
    serializable and can be passed around. However, you are likely
    not able to pass the original iterator or its EmpColl subclass
    around.

  • No-args constructor and Serialization

    Gurus,
    From the Serializable Interface JavaDocs, we have:
    "To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error will be detected at runtime.
    During deserialization, the fields of non-serializable classes will be initialized using the public or protected no-arg constructor of the class. A no-arg constructor must be accessible to the subclass that is serializable. The fields of serializable subclasses will be restored from the stream. "
    Can you please tell me what does this mean in plain English!!
    I tried all the possiblities, that I can think of, to do serialization and deserialization, and I didn't find any situation that I was forced to have a no-args constructor (since the VM is always providing me with one).
    Thanks in advance...

    well.....look at this example:
    import java.io.*;
    public class Test
       public static void main(String[] args) throws Exception
          Test test = new Test();
          Test1 test1 = new Test1(new String(""));
          test.serializeObject(test1);
       public void serializeObject(Object obj) throws IOException
          File file = new File("serializedTestObject.ser");
          FileOutputStream fos = new FileOutputStream(file);
          ObjectOutputStream oos = new ObjectOutputStream(fos);
          oos.writeObject(obj);
          oos.close();
          fos.close();
    class Test1 extends Test2 implements Serializable
       Test1 (String str)
          super(str);
       int x = 15;
    class Test2
       Test2 (String str)
       int y = 10;
    }D:\test>javac Test.java
    no compilation errors
    D:\test>java Test
    it ran without any problems
    D:\test>dir ser*.ser
    12/01/2005 07:44a 34 serializedTestObject.ser
    it really created the file
    In this example the the child class implemnets Serializalbe, while the parent class doesn't. The parent class didn't implement a no-args class (implicitly or explicitly), and still ti compiles and runs.
    This example was compiled and run using Java 1.5.

  • Javabeans in MVC architecture

    Hi
    Building a web application based on MVC architecture. I am new at this so my implementation may not be correct. My Javabeans are representations of SQL DB tables. So, e.g. I have a Customer table in my SQL database, I would have a CustomerBean to represent this table.
    My problem is that Javabeans can only have empty constructors. So how can I get a single record from my customer table? Currently, I am using a method to get this record.
    E.g.
    CustomerBean customer = new CustomerBeanImpl();
    customer.setRecord(primaryKeyOfCustomerTable);
    In setRecord(int PK) method, I execute a SQL query to retrieve the record with that primary key and set all the instance variables for that object.
    I find that this method "not elegant".
    However, if I break the requirements of Javabeans, i.e to implement non-empty constructors, i.e.
    Customer customer1 = new Customer(primaryKey1);
    this would be better. In this case, my class is not a JavaBean anymore.

    Thanks. So, I conclude from your reply that Javabeans
    must have empty constructors. That's what I thought
    too. Until I was looking at an example from "Core
    servlets and JSPs" and came across an example where
    the class used (if anyone is interested, it is
    "TravelCustomer.class" in page 365 of the book) is not
    an Javabean per se, as it did not have a empty
    constructor but was used in the <jsp:useBean> tag like
    any other Javabean!
    That got me confused. Anyone care to explain this?As you know, <jsp:useBean> first checks whether a reference to the specified class exists as an attribute under the specifed id and scope.
    If the reference is found, then the scripting variable is set to that reference. If not found, then <jsp:useBean> checks whether the class can be instantiated and has a no-args constructor. If yes, an object of that class is instantiated (in Tomcat using Beans.instantiate) and the reference is stored as an attribute in the specified scope as well as in the scripting variable.
    In the "Core Servlets..." example, the TravelCustomer object is always instantiated in a servlet and its reference saved as a session attribute with id = "customer". The servlet then forwards to a JSP that includes:
    <jsp:useBean id="customer" class="coreservlets.TravelCustomer" scope="session" />Since the "customer" attribute is always present, the useBean never has to instantiate a TravelCustomer object and so the lack of a no-args constructor does not come into play.
    I'm not sure if this is good or bad practice, but that's why it works.

  • Why JavaBean is called "JavaBean"

    i'm just wondering why JavaBean is named like that....?!?

    Any javabean that's going to be halfway useful probably is going to do signficantly more than just provide a no-arg constructor. Providing a no-arg constructor is a minimum (and only) requirement for a class to qualify as a bean, but "JavaBean" shouldn't be seen as just a synonym for "class with a no-arg constructor" -- it ignores the context of how they're meant to be used.
    That's why I think that "a class that Introspector knows how to make sense of" is a more useful definition. If you hand a class with a no-arg constructor to Introspector, it doesn't barf, so yes, technically it's a bean -- but if you can then do something useful with that class, then not only technically but practically it's a bean.
    Once I had to fix code where a "bean" didn't follow the conventions correctly, and so although technically it was still a bean, Introspector couldn't use it (following a JDK upgrade -- long story) and code died. The fact that it technically qualified as a bean was irrelevant. The important part was that the "bean" was supposed to behave in certain beanish ways given its purpose, and it didn't.

  • JUnit test fixture where constructor of base object throws exception

    I'm trying to construct a test case which requires an object whose constructor currently throws and exception (it tries to make a connection which isn't currently available).
    Now normally the trick would be to construct a test fixture class which extends the base class and returns the stuff I want. The trouble is I can't cope with an exception in in super constructor. Is there any way out of this, short of refactoring the offending base class?

    Just use the no-arg constructor of RootRenderingContext, and all should be defaulted appropriately.

  • NewInstance & constructor of base class

    When I instantiate a sub class directly (using new), the code in the constructor method of both base and sub classes run.
    When I instantiate using java.lang.reflect.Constructor.newInstance, only the sub class's constructor method is invoked. Is there a way to force running the constructor method of the base class as well?
    Thanks & Regards.

    when I tried to build a simple code to show the problem, I realised that the problem is somewhere else - Still not solvable by me - Please help.
    Irrespective of whether new or Constructor.newInstance -
    The constructor method with appropriate signature is invoked from child class.
    The constructor method without any arguments is invoked from parent class. - This is the reason for my original problem.
    In the attached code, the variable xyz is not getting assigned proper value (from the argument a).
    public class Mainer {
       public static void main(String args[]) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, java.lang.reflect.InvocationTargetException
           int inArg = 5;
           System.out.println("With new");
           ChldClass chld1 = new ChldClass(inArg);
           chld1.m1();
           System.out.println("With Constructor.newInstance");
           java.lang.reflect.Constructor ArgsConstructor;
           Class[] argsClass = new Class[] {int.class};
           Class chld2Class = Class.forName("ChldClass");
           ArgsConstructor = chld2Class.getConstructor(argsClass);
           Object[] argsObject = new Object[] {5};
           ChldClass chld2 = (ChldClass)ArgsConstructor.newInstance(argsObject);
           chld2.m1();
    class PrntClass
        int xyz;
            public PrntClass(int a)
                xyz = a;
                System.out.println("Int Arg Constructor within Parent Class <<<" + xyz + ">>>");
            public PrntClass()
                System.out.println("Default Constructor within Parent Class");
         public void m1()
              System.out.println("M1 of Parent Class");
    class ChldClass extends PrntClass
        public ChldClass(int a)
            System.out.println("Int Arg Constructor within Child");
         public void m1()
              System.out.println("Value of xyz "+xyz);
         public void m2()
              System.out.println("M2 of ChldClass");
    The result displayed:
    With new
    Default Constructor within Parent Class
    Int Arg Constructor within Child
    Value of xyz 0
    With Constructor.newInstance
    Default Constructor within Parent Class
    Int Arg Constructor within Child
    Value of xyz 0
    Thanks & Regards.

  • Not getting the use of 'this' keyword in constructor as shortcut approach.

    class Box{
    int width;
    int height;
    int depth;
    Box(){ //no-arg constructor
    Width =1;
    Height = 2;
    Depth = 3;
    Box(int width){
    this.width = width;
    height = 2;
    depth = 3;
    Box(int width, int height){
    this.width = width;
    this.height = height;
    depth = 3;
    /*Box(int width, int height, int depth){
    this.width = width;
    this.height = height;
    this.depth = depth;
    *//short cut approach*
    *Box(int width, int height, int depth){*
    this(width, height); //calls matching constructor from the same class
    this.depth = depth;
    Box(Box b){
    this.width = b.width;
    this.height = b.height;
    this.depth = b.depth;
    public class ConstructorDemo {
    public static void main(String[] args) {
    Box b1 = new Box(1,2,3);
    Box b2 = new Box(b1);
    In the above example, 'this' pointing to current object is understood but
    this(width, height); is used instead of this.width=width; this.height=height;
    how can it be shortcut when we have declared constructors ? And really how its so useful in a big code?
    Edited by: 1010533 on Jun 7, 2013 12:54 PM

    Welcome to the forum!
    >
    class Box{
    int width;
    int height;
    int depth;
    Box(){ //no-arg constructor
    Width =1;
    Height = 2;
    Depth = 3;
    Box(int width){
    this.width = width;
    height = 2;
    depth = 3;
    Box(int width, int height){
    this.width = width;
    this.height = height;
    depth = 3;
    /*Box(int width, int height, int depth){
    this.width = width;
    this.height = height;
    this.depth = depth;
    //short cut approach
    Box(int width, int height, int depth){
    this(width, height); //calls matching constructor from the same class
    this.depth = depth;
    Box(Box b){
    this.width = b.width;
    this.height = b.height;
    this.depth = b.depth;
    public class ConstructorDemo {
    public static void main(String[] args) {
    Box b1 = new Box(1,2,3);
    Box b2 = new Box(b1);
    In the above example, 'this' pointing to current object is understood but
    this(width, height); is used instead of this.width=width; this.height=height;
    how can it be shortcut when we have declared constructors ?
    >
    Shortcut? Who said it is a shortcut?
    >
    And really how its so useful in a big code?
    >
    EXTREMELY useful - especially in 'big code' (whatever you mean by that).
    Constructors are meant to create VALID instances. The business rules for creating a valid instance may not be as simple as your example.
    Ideally code should be written once and used often. The use of constructors is no different.
    Once you have a contructor for a given set of arguments you should use it if you need to construct an instance like that.
    So when you need a constructor that uses those same arguments and then some additional ones your new constructor should call the existing constructor and should then apply the new logic needed for the new constructor.
    That is important because it means that the business logic needed for those two arguments is only implemented in ONE place. That logic might be very complicated and there is no valid reason to duplicate it.
    Once you have a piece of code that works reuse it whenever possible.

  • Create an object instance without calling its constructor?

    Hi,
    Sometimes it's useful to create object instances without calling their constructor. When? For example object deserialization.
    By default when deserializating an object, the instance in the VM is created by calling the default constructor of the first non Serializable super-class (if you don't have such you're in trouble). I think that the db4o object database don't even call any constructor you may have written.
    So such thing exists, but how is this possible? I fugured out that sun's deserialization mechanism first finds the constructor of the first non Serializable super-class and then:
    cons = reflFactory.newConstructorForSerialization(cl, cons); Here I'm stuck.
    Here's the source of the method for finding serializable constructor:
         * Returns subclass-accessible no-arg constructor of first non-serializable
         * superclass, or null if none found.  Access checks are disabled on the
         * returned constructor (if any).
        private static Constructor getSerializableConstructor(Class cl) {
         Class initCl = cl;
         while (Serializable.class.isAssignableFrom(initCl)) {
             if ((initCl = initCl.getSuperclass()) == null) {
              return null;
         try {
             Constructor cons = initCl.getDeclaredConstructor(new Class[0]);
             int mods = cons.getModifiers();
             if ((mods & Modifier.PRIVATE) != 0 ||
              ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
               !packageEquals(cl, initCl)))
              return null;
             cons = reflFactory.newConstructorForSerialization(cl, cons);
             cons.setAccessible(true);
             return cons;
         } catch (NoSuchMethodException ex) {
             return null;
        }So any info about this ReflectionFactory, and the problem as a whole?
    Thanks.

    So the question is how to create object instance without initializing it (calling the constructor)? And if you have any info about ReflectionFactory it will be useful too.
    When serializing an object you save all its fields and some extra info. When you deserialize it you have to reconstruct it, by copying the fields back, but not to reinitialize.
    import java.lang.reflect.*;
    import java.io.Serializable;
    import java.security.AccessController;
    import sun.reflect.ReflectionFactory;
    public class Test0 implements Serializable {
        public Test0() {
            System.out.println("Test0");
        public static void main(String[] args) throws Exception {
            Constructor<Test0> constr = reflectionFactory.newConstructorForSerialization(Test0.class, Object.class.getConstructor(new Class[0]));
            System.out.println(constr.newInstance(new Object[0]).getClass());
        private static final ReflectionFactory reflectionFactory = (ReflectionFactory)
         AccessController.doPrivileged(
             new ReflectionFactory.GetReflectionFactoryAction());
    }When you execute this piece you get:
    class Test0

  • Constructor calls in initialization lists

    Hello!
    I've encountered a difference in behavior between Solaris Studio 12 update 1 (CC: Sun C++ 5.10) and g++ that has me baffled.
    This is seen when a class's constructor features an initialization list before the start of its body. It seems that when I use a constructor call to initialize a member variable in the list, Solaris Studio calls that constructor once for the temporary object that is between parentheses and a second time to initialize my class's member variable with a copy constructor using the former temporary object. g++ by contrast calls that constructor only once.
    Here's a testcase that should hopefully clarify my point. The initialization list is in class Foo's constructor:
    File: "foo.h"
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    class Bar {
         size_t length;
    public:
         Bar(){
              std::cout << "Bar no args constructor. This: " << this << std::endl;
         Bar(size_t length){
              std::cout << "Bar length constructor. This: " << this << std::endl;
         Bar( const Bar& ) {
              std::cout << "Bar copy constructor. This: " << this << std::endl;
         virtual ~Bar(){
              std::cout << "Bar destructor. This:" << this << "\n";
    class Foo {
    private:
         int alpha;
         Bar bravo;
    public:
         Foo(int length);
    };File: "foo.cpp"
    #include "foo.h"
    Foo::Foo(int len): bravo(Bar(len)) {
         alpha=len;
    }File: "testcase.cpp"
    #include "foo.h"
    #include <unistd.h>
    int main( int argc, char** argv) {
         Foo testcase(4);
         usleep(2000000);
         std::cout << "Program end of life" << std::endl;
         return EXIT_SUCCESS;
    }When I compile these files with Solaris Studio...
    $ CC -library=Crun,Cstd  -o ./foo.o -c ./foo.cpp ; CC -library=Crun,Cstd -o ./sol_studio_testcase ./testcase.cpp ./foo.o...the testcase program produces this output:
    $ ./sol_studio_testcase
    Bar length constructor. This: 8047744
    Bar copy constructor. This: 804777c
    Bar destructor. This:8047744
    Program end of life
    Bar destructor. This:804777cBy contrast, when I use g++...
    g++ -o ./gfoo.o -c ./foo.cpp; g++ -o ./gplusplus_testcase ./testcase.cpp ./gfoo.o...the output shows only one call to a contructor for class Bar:
    Bar length constructor. This: 0x8047784
    Program end of life
    Bar destructor. This:0x8047784I'm working on a fairly large g++ codebase that makes heavy use of initialization lists throughout and relies on g++'s behavior in this regard (there's some vital memory management baked in the constructors and destructors).
    So would anyone here know if/how I could induce Solaris Studio's CC to behave like g++ in this case?
    Best regards,
    - Matt Boyer

    In the initialization
    Foo::Foo(int len): bravo(Bar(len)) { ... } the program semantics call for creating an anonymous temp object of type Bar that is used to initialize the bravo member of Foo, and later destroyed.
    The C++ standard allows, but does not require, an implementation to eliminate the temp object in some circumstances. The Sun/Oracle C++ compiler does not currently have this optimization.
    But there is no reason in this case to write bravo(Bar(len))+, because bravo is already of type Bar. If you write the simpler code bravo(len)+, no temp object is implied or created by the compiler.

  • Why Do We Need Constructor With Arguments?

    I understand that constructor is used to create instances.
    We can have constructors with 0 argument or with one/multiple arguments. Why do we need a contructor with arguments? What is the purpose of doing it?
    Thank you for your help.

    There are three general ways to provide constructors, like you said:
    1) Default constructor (no arguments)
    2) One or more constructors with arguments
    3) One or more constructors with arguments as well as a default constructor
    From a design standpoint, the idea is to give as much information needed for constructing an object up front. Look at the standard Java API for some examples (and because I couldn't find a standard class with just a default constructor, one made up):
    public class Foo {
      private long createTime;
      public Foo() {
        createTime = System.currentTimeMillis();
      public String toString() {
        return "This object was created at " + createTime;
    }This code has no reason to take any arguments. It does all construction on its own and already has all the information it needs. On the other hand, look at BufferedReader. There's no possible way this object can ever be constructed without an argument. What's it buffering? It doesn't make sense to ever instantiate new BufferedReader(). It'd be useless. So BufferedReader has no default (no-arg) constructor.
    Sometimes (very often in Java) you want to do both. Let something be instantiated with no arguments, but also provide the option of creating something with more specific details. A good example is ArrayList, which has three constructors:
    public ArrayList() --> Construct an empty ArrayList with the default initial capacity;
    public ArrayList(Collection c) --> Construct an ArrayList populated with the contents of another collection;
    public ArrayList(int capacity) --> Construct an empty ArrayList with a specific initial capacity.
    Sometimes it makes sense just to use the default. Sometimes you want more control over the behavior. Those are the times to use multiple constructors.
    Hope this helps!

  • Throw difference exception in constructor

    Have a base class constructor that throws an exception of class XException
    Have an exception class YException that inherit exception XException
    If I inherit the base class, can I make it throw exception Y instead of X, since Y is a subclass of exception X?
    Example:
    public class Base {
    public Base() throws XException {
    public class XException extends Exception {
    public XException() {
    // etc...
    public YException extends XException {
    YException() {
    super();
    public MyClass extends Base {
    // Can this work in a constructor since YException is a subclass of XException?
    // Anyway to make this possible?
    public MyClass() throws YException {
    super();

    Have a base class constructor that throws an exception
    of class XException
    Have an exception class YException that inherit
    exception XException
    If I inherit the base class, can I make it throw
    exception Y instead of X, since Y is a subclass of
    exception X?
    Example:
    public class Base {
    public Base() throws XException {
    public class XException extends Exception {
    public XException() {
    // etc...
    public YException extends XException {
    YException() {
    super();
    public MyClass extends Base {
    // Can this work in a constructor since YException is
    a subclass of XException?
    // Anyway to make this possible?
    public MyClass() throws YException {
    super();
    Apart from what you are asking in normal circumstances a no args constructor throwing an exception is never a good idea. The reason being that from then on anybody who extends this class would have to face problems. Consider the following
    public class MyTest
          public MyTest() throws Exception
    class Test extends MyTest
    {}this would not compile and throw the following error
    Default constructor cannot handle exception type Exception thrown by implicit super constructor. Must define an explicit constructor     
    So thats not a good practice
    cheers

Maybe you are looking for