Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2008, 10:41 AM
Member
 
Join Date: Jul 2008
Posts: 2
vital parsley is on a distinguished road
how does this code work...explain me the execution please...
public class ques4thir
{
public static void main(String args[ ])
{
SuperClass object=new SuperClass( );
object.display( );

object=new SubClass( );
object.display( );
}
}

class SuperClass
{
private int privatevar=10;
public int publicvar=20;
protected int protectedvar=30;
int defaultvar=40;

public void display( )
{
System.out.println(privatevar + ":"+publicvar+" :"+protectedvar+" :"+defaultvar);
}
}

class SubClass extends SuperClass
{
public SubClass( )
{
this(10);
}

public SubClass(int a)
{
super( );
super.publicvar=super.publicvar+1;
this.protectedvar=this.protectedvar+1;
this.defaultvar=this.defaultvar+1;
}
}

which method gets executed first...i m a bit confused!..tried using system.out.println to see wat gets executed first..but tat only increased trhe confusion!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2008, 11:27 AM
Alan-LB's Avatar
Member
 
Join Date: Jun 2008
Location: Junee, NSW, Australia
Posts: 19
Alan-LB is on a distinguished road
Send a message via Yahoo to Alan-LB
Ask yourself which statement in the program gets executed first. Then which is the next. Write them down on a piece of paper and work slowly through the whole program.

By the way - wat is spelled 'what' and tat is spelled 'that'!

Alan
__________________
There are 10 types of people - those who understand binary and those who don't!!
Today is the Beta version of Tomorrow!!
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-24-2008, 05:46 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
To see who calls the display() method, add an arg to it that indicates who the caller is and show that value in the println();
For example:
object.display("main with superclass");
object.display("main with subclass");
The output now will show you the execution flow.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-25-2008, 06:50 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes do it as Alan and Norm says. If you stuck with something ask your question as much as clearly you can.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please explain Java MarkWilson New To Java 7 07-02-2008 10:38 AM
the code dosent work pcman Java 2D 1 03-20-2008 10:20 PM
Need Help Can anyone explain what this means Clemenza1983 New To Java 6 02-16-2008 05:13 AM
Iam new in Java Please explain to me vinaytvijayan AWT / Swing 1 12-30-2007 01:35 PM
need to explain this code reached New To Java 3 12-04-2007 12:01 AM


All times are GMT +3. The time now is 01:04 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org