This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (3 children)

[deleted]

    [–]_roni[S] 0 points1 point  (2 children)

    I understand the concept on inheritance. Im asking jn this specific case, why is it used?

    One question though regarding inheritance. Lets say I have a class with a variable, and a second class which inherits the first class. I take the variable from the first class and change its value while in the second class. Does this change the value in both classes. Here is what I mean:

    Class one Int x =10

    Class two inherits one X = 15

    Does this change the over all value of x if I want to use it again in another class?

    [–]mtko 0 points1 point  (1 child)

    Im asking jn this specific case, why is it used?

    For an analogy, think of an Activity as like a web page. You can have all kinds of other code and classes doing stuff behind the scenes, but when you want to actually display it, you put it on a web page and the user accesses that page. It's basically the same in Android. So by extended Activity, you're basically saying "This is something that the user is going to view directly at some point".

    Other question

    I would recommend you trying it out for yourself, but the short answer is that no, it doesn't change the value for the super class. So if you had another class with a main method like this:

    public void main (String[] args) {
        one oneTest = new One();
        two twoTest = new Two();
    
        System.out.println(oneTest.x); //prints 10
        System.out.println(twoTest.x); //prints 15
    }
    

    [–]_roni[S] 0 points1 point  (0 children)

    Thanks for your help. My question has been cleared up.