Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Jegon Jeganathan Renganathan

Greenhorn
+ Follow
since Apr 21, 2006
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 Jegon Jeganathan Renganathan

What if you have a class B that extends class A and they don't have any instance methods/vars--only static.

It is a good question. But let me ask you something first, what is the reason for class B to extend class A? As far as i know If you extend a class, then you wish to say to JVM that you already have some functions in a class A which you wish to override in class B. If you don't want any methods to be overriden the entire concept of extending that particular class will be of no use.
Hi Hasaan,

A good question. As mentioned by one of our friend,
String s= "hello"; //will create only one object in pool
String s = new String("hello");//will create two objects
As far as we are using the first line(which most of us are using) for creating string object, it will be stored in Magical (String pool) which is not eligible for GC.
But, as the second statement which is created in the Heap will be eligible for GC. Hope this will be clear for you.
Hi,
Congratualtions on Clearing TIGER Edition of Java.
I am also preparing for the exam. Please share your comments and throw some suggestions how to prepare for the exam?? How long did you spent daily to complete the 798 pages of K&B.How did you revised it. What are all the mock exams have you gave?? Please give us some mock engine for 5.0.... Thanks in Advance...
14 years ago
Hi Bert!

I am preparing for SCJP 5.0 Tiger edition. As everyone in the loop is mentioning about the toughness of the exam very few have actually discussed about the advantage of having the latest certificate. This not only hones you to the "Tiger" edition of Sun but also gives us the pleasure to learn the advancement in the SUN World. Hope to get the better grades in the Exam. And your valid suggestions to prepare for the exam will be grateful to all of us!!!
To my knowledge if you don't have any constructor in Super(Parent) class then, the JVM will add a "Default Constructor" which is nothing but a empty constructor like the one given below
MySuper(){}
So even if you create any Constructor in child class it will not lead to compilation issue. But if you added an explicit constructor say
MySuper()
{
System.out.println("MySuper");
}
Then in the child class you need to add the super() explicitly or else it will leads to a Compilation issue.
MySub()
{
super();
System.out.println("MySub");
}
Hope you are clear now.

By the way the output for your code is

It will execute the Parent(Super) constructor first (Because the Object reference is of MySuper type) and then only the MySub(Child) will be executed.

so the output is

super2
sub

Originally posted by RAGU KANNAN:
Hello,

How this code is compiled, the MySuper class without call to super(). I ready the book it says any one of the constructors in a class should call the super ().
Pls correct me if I am wrong.

1. class MySuper {
2. public MySuper(int i) {
3. System.out.println("super " + i);
4. }
5. }
6.
7. public class MySub extends MySuper {
8. public MySub() {
9. super(2);
10. System.out.println("sub");
11. }
12.
13. public static void main(String [] args) {
14. MySuper sup = new MySub();
15. }
16. }


Thanks, Raghu.K