Forums Register Login
two public classes in same source file?
Today I have given a code

public class A
class B b;

public class B
class A a;

and he asked is there any error??

I told him we can't place two public classes in a single source file..He said no it is possible.

then he changes the code as

public class A
class B b; // line no1

protected class B
class A a; // line no2

then I said line no1 n line no2 has error.
He was not satisfied, I said this forward declaration is allowed in c++ not in java..

Then at the end of the interview I again said him that its not possible...
he said it is possible either he was joking or I am mad or may be I don't know much....
Please suggest some thing...
They all have errors; you can't just put "class" keywords in random locations.

Other than that--what do you think? What happened when you tried it?

(The idea of "forward declarations" isn't necessary in Java; classes can be defined in any order.)
David Newton wrote:They all have errors; you can't just put "class" keywords in random locations.

Agreed. In order to have a viable debate on a particular of the language, you actually need valid language constructs.

Otherwise, the debate is simple -- Syntax error. Won't compile. Period.

But I don't know what he was trying to do with me...
We don't either--if that was the exact code you were given, and it's supposed to be Java, it's just plain wrong.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Oct 24, 2017 04:24:42.