Campbell Ritchie wrote:
Not at all. It should be the other way round.Andy Jack wrote: . . . So, use an IDE and and learn the basics taught in the SCJP book quickly. Once you learn all the basics, you can do all your coding without an IDE. . . .
Learn to use an IDE after you are experienced in the use of text editors and the command line or terminal
Terry Tucker wrote:Thanks for the reply and advice. I am using command line and vim for this because the SCJP Study Guide recommended putting aside the IDE. I did create a couple classes as you suggest and have shown that both constructors and methods, without an access modifier specified, behave with "default" access.
Again, thanks for the help...
Terry Tucker wrote:Greetings Moose People:
I would like to know if a constructor that has no access modifier explicitly stated behaves the same as a class that is declared without an access modifier; that is, does if have "package access" (default)? What about methods? When no access modifier is supplied, do they have package access?
Thanks for the input...
bharat bhasin wrote:Thank you Andy for your answer .
But I don't understand the explanation .
You say the "this" is a reference of class A , OK I got it .
But I don't understand why it cannot see the show() method of class B . I know it is private and not visible to class A but the JVM checks whether its present in class B and it is present .
I didn't understand how this whole thing works .
bharat bhasin wrote:I wrote a program as follows :
public class A {
private void show() {
System.out.println("A()");
}
public void value() {
this.show();
}
public static void main(String[] args) {
A obj = new B();
obj.value();
}
}
class B extends A {
private void show() {
System.out.println("B()");
}
}
I was expecting the output to be this " B () " , but the output comes out to be : "A ()".I don't understand this . . Now after using "this.show()" I expect the method show belonging to class B to be called instead of the method of the class A , because of the following reasons :
1. show() is a private method in class A , so class B doesn't extend it .
2. I have assigned an object of type B to the reference of class A .
3. I am using the "this" operator with show() , so I expect that the method from class B should be called but show from class A is called instead .
Can anyone please this behavior ?
fred rosenberger wrote:If we take all the chaff out of your toString method, we are left with this:
That line 4 is a call to a method. The method you are calling happens to be itself. Which then calls itself. Which then calls itself...
Lucy Rai wrote:Please tell me answer. I am java fresher.