shailu kommineni

Greenhorn
+ Follow
since Jan 26, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by shailu kommineni

Ok, I have read about polymorphysm. I am really embarassed now.
Thanks for your answers.

Shials
20 years ago
1. If C expects an object of A but you are passing an object of B. If in the method twidleA C is creating an object of A and on the instance of A calling some private methods of A, then can it do the same when you pass an object of B?
2. Also I pass B to twiddleA method of C which has a serveNoodles method. It will use a method of A say, cookNoodles which boils noodles without frying them but same method of B will fry them and then boils. C expects some behaviour but a different behaviour results when you pass a different ( subclass) object of A (B). Then how can you say that everything works fine?
3. What is the best book to study java if I want to know what exactly happens behind the scenes as well?

Shials
(I am really thrilled to receive response from an author!! Is your book on java? Then you will obviously say it is the best book? )

Originally posted by Ernest Friedman-Hill:
Hi,
Welcome to JavaRanch!

Because anything that some other class C can do to an A object, it can also do to a B object; for example, if C has a method twiddleA() which accepts an A as a parameter, you can pass a B when you call it, and everything works fine.
[ January 26, 2004: Message edited by: Ernest Friedman-Hill ]

20 years ago
I have recently started studying java programming language and have these few questions.
What does it mean when you say java garbage collects any unused objects? I have compiled a java programme( .java is created) and then ran it using the class name. I presume it is at this point that an object is created. Once the program is run the object created should go as far as I understood. Is that right? So any object that is creatd should be garbage collected once it is run, right? Why is there a big deal on "when to garbage collect an object"? I know my understanding is not very clear, what am I missing? If some other porgram is running which uses this program then it can't be garbaged. But if there is nothing else that is referencing this program, it will be garbage collected, right?
What is the difference betweeen creating an object on stack and creating them on heap? If performance is such a big issue, why not create the objects on stack itself( is stack a limited resource?)?
This is on inheritance ->
I have a class which extends another. If I create an object of the class B (extending A) do I have access to all the private methods of the class A?

A a = new B().
Can I access a.somePrivateMethodOfA ? If yes how is private? If not how exactly "is" B A?
I know, I have to read a little more. But I am not moving forward, it is too confusing and I thought I could use some help.

Thanks.
Shails
20 years ago