Question: I'm trying to retrieve the names of the table from the local database I'm using.

This the code I've tried but it never goes through the foreach loop:

```
public void GetColumnNames()
    {
        SqlConnection con;
        SqlDataAdapter adapter = new SqlDataAdapter();
        DataSet ds = new DataSet();

        con = new SqlConnection(Properties.Settings.Default.AlhusainSoundDBConnectionString);

        List<string> colns = new List<string>();

            try
        {
            con.Open();
        }
        catch (SqlException ex)
        {
            MessageBox.Show(ex.Message);
        }

        foreach (DataTable dt in ds.Tables)
            {
                colns.Add(dt.TableName);
                Console.WriteLine(dt.TableName);
            }
    }

```

So could anyone please suggest me how to do that correctly

Regards

Answer: 
The constructor of the super class A (which calls `initialize()` which calls `B`'s `initializeLayout()`) is executed before the instance variables of the sub-class B are initialized. Therefore your instance variable `myVariable` is still null at that time.
The (possibly implicit) constructor of the child B will do the following:

* have all fields zeroed (null, 0, 0.0, false)
* call the constructor of super A
* + call B.initializeLayout with all fields null
* initialize all fields that are assigned to in their declaration
* call the rest of the constructor

So what you are attempting are doing is very error prone in java.
Many style checkers mark this code as bad style (**calling non-final method in constructor**).

You may do

```
private /*final*/ Object myVariable; // Must not be initialized!

@Override
protected void initializeLayout() {
    myVariable = new Object();
    // Do something with myVariable
}

```

Having myVariable initialized would initialize myVariable after the call to initializeLayout.

Better to avoid.