Wednesday, November 14, 2012

Nested~

for most programmers or IT ppl who did coding before,
I am sure you know what it meant by nested.

As for non-IT literate ppl, i will explain what it meant by nested.
Have u watched Inception? Its about a movie about how these ppl
can go into ppl's dream.
And the interesting part is when they go into a dream within a dream.
Sometimes, it maybe a dream within a dream within a dream.(3 levels).

If u did not watched it yet, then u have no life~

So, back to nested.
We normally have nested loop, nested if-else statement, nested queries and so on.
What i learned recently was nested class in java.
Example,

public class Admin extends users{
    public Admin(){
    }
    public class SubAdmin1 extends JInternalFrame{
        public SubAdmin1(){}
    }
    public class SubAdmin2 extends JInternalFrame{
        public SubAdmin2(){}
    }}

So, as u can see, SubAdmin1 and SubAdmin2 are nested inside the Admin class.

Now, in ur main class u can declare something like

private Admin ad;
private Admin.SubAdmin1 sub1;
private Admin.SubAdmin2 sub2;


And then to use it in ur main class constructor, u declare it by doing,

Admin ad = new Admin();
sub1 = ad.new SubAdmin1();
sub2 = ad.new SubAdmin2();


okay, the end~

No comments: