Mohammad Hossain

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

Recent posts by Mohammad Hossain

class A
int x=5;

class B extends A
int x=6;

class SubClass extends EPractice$1$5
public B getObject(){return new B();}

public class EPractice$1$5
public A getObject(){return new A();}
public static void main(String[] args)
EPractice$1$5 e=new SubClass();

If you look carefully, you can see that this is not overriding, it is overloading. So, when you say e.getObject(), it is calling EPractice$1$5(superclass)'s method, and it returns and object A.
Then it is calling A.x, and prints 5.
I hope it would help you.
I have faced the same comments many..... times.
All I can tell you is
There are a lot of stupid people in this world, and just don't care about them.
public int B(String s)

This is not a constructor. This is a method, having the same name as constructor. Because constructors have no return types.
How would you get access to the private member x. You need a public method, or you need to make the variable public.
As far as I know. Its not overriding. I mean HankyPanky class doesnot know anything about HumptyDumpty's myMethod(). So in HankyPanky its HankyPanky's myMethod(). I mean from HankyPanky's point of view there is no myMethod() in
HamptyDumty so it is writing its own method.
What is the meaning of while(true).
Bccause, it looks like the program will run forever. I mean the while loop will never stop.
Ya thats right.
I would suggest read some books, try some examples, find out some specific questions and post them here.
Because only a forum is not enough to explain overloading. There are many exceptions. And if people don't explain all of them to you. You will become more confused.
If that sounds offended I am really sorry for that. I just wanted to help.
Hi Seema,
You cannot access the private memebers of any class outside the class scope, as a result OverRidingTwo cannot access the private variables i and j of OverRidingOne.
But if you wish to access the variables of the parent class in child class then you must first make those visible in the child class and then use super keyword to access them so now say Parent class has a variable xyz marked with default/public/protected access then you can access its value in child class using and in same way you can invoke the super class methods using super.display(1,2) in your child class.
Hope this clears your doubt.

I agree with Mr. Deepak jain.
I believe the program was not a good one. Because if I was writing the super class. Then I would use some public methods like getI() to access i, which would be available to all the subclasses. And thats how we can use the super class's variables in the subclass's method.
Animal is the superclass of Horse. So, Horse is also a kind of Animal. Because of that it is possible to assign Horse object to Animal.

Here we are creating an Animal reference by "Animal animal", but when we say new Horse() we are creating a "Horse object". So the variable animal is a reference to a Horse object. Animal is actually a Horse. that's why its calling Horse's eat() method.
Its not that hard.
because when (j=0;j<=60;j+=15)
then you get j=0,15,30,45,60
when (j=1)
you get j=1,16,31,46

Look when you said j=0, then the loop will run (5 times for j)*(4 times for i) so total 20 times; however, interval can have 17 elements. so when it gets interval[18] gives you error.

Then when you use j=1. The loop would run (4 times for j)*(4 times for i)
so total 16 which is valid for interval, and it works.
16 years ago
It looks like that you have not initialized Object O. So, it gives a compiler error. Are you using javac and java command or some IDE.
16 years ago
As far as I know
when you use javac or java they search for files in the directories that are in '$classspath' variable. Thats why before you use javac you need to make sure that the directory containing the java file is in your classpath.
16 years ago