Results 1 to 6 of 6
Thread: get my conecpts right , please !
- 12-13-2010, 01:27 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 38
- Rep Power
- 0
get my conecpts right , please !
why the following things cannot be :
1.why i cannot extend the non static variable from static method or something ?
2.why i cannot use a variable directly in the class as :
3. How i can make such a program that would continously generate objects and keep on extending classes automatically and gets up all the memory of the system until the system crashes.Java Code:class abc{ int i=4; } class xyz extends abc{ int j=7; i=9; /*this should be valid acc. to me bcz i think that when a class is extended then the variable are also inherited and now the class xyz has i and j both accesible so it should be able to change the variable value also. */ }
tell me also something more about these object concept tricks and tips...PLEZ
- 12-13-2010, 02:03 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Please at least let people know that you are cross-posting.
- 12-13-2010, 02:12 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Pardon? I didn't understand the question.
If that's your code as written then that's a compiler error since:
i=9;
can only be in a method or code block.
Why on earth do you want to do 3? But using up all the memory in a system is a simple task of looping and adding "new Object()" to a List of some description. No need to extend classes.
- 12-14-2010, 07:21 AM #4
Member
- Join Date
- May 2010
- Posts
- 90
- Rep Power
- 0
you can place it in a method
public void method1()
{
i=9;
}
to run out memory just place an instance of same class inside it. it works recursively.
class A
{
A objA = new A();
}
- 12-14-2010, 07:37 AM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 12-14-2010, 07:42 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Because "non-static" is bound to the instance of a class and "static" is bound to the class itself. Two very different things.
If the variable is declared to be private only that class has access to it, if it is declared default (i.e. no access modifier, as above) only that class or other classes in the same package can access it, if it is declared protected, that class, other classes in the same package, and subclasses have access to it, and with public all classes have access to it.2.why i cannot use a variable directly in the class as :
Java Code:class abc{ int i=4; } class xyz extends abc{ int j=7; i=9; /*this should be valid acc. to me bcz i think that when a class is extended then the variable are also inherited and now the class xyz has i and j both accesible so it should be able to change the variable value also. */ }
A while loop that creates objects and adds them to a list.3. How i can make such a program that would continously generate objects and keep on extending classes automatically and gets up all the memory of the system until the system crashes.
tell me also something more about these object concept tricks and tips...PLEZ
Now, I hope that this homework is already past due and that you got the grade that you seemingly deserve.


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks