Stack Trace in JAVA

To trace a method call :

StackTraceElement[] myStack=Thread.currentThread().getStackTrace();
for (StackTraceElement myStackElement : myStack){
System.out.println( myStackElement);
}

//———————————————————————————-
//     Name: InheritanceTest.java
//     Purpose: <Description of the file>
//     Author: syadav

//     Date: Jul 28, 2010

//    @ Copyright Amdocs Israel, 2004.
//    This document contains proprietary and confidential
//    information, and shall not be reproduced, transferred, or
//    disclosed to others, without the prior written consent of Amdocs.
//————————————————————————————————

package com.test;

public class InheritanceTest
{
public static void main (String[] args)
{
Child chld=new Child();
chld.print(“Hi”);
}
}

class Parent{

public final void print(String str){
StackTraceElement[] myStack=Thread.currentThread().getStackTrace();
for (StackTraceElement myStackElement : myStack){
System.out.println( myStackElement);
}
System.out.println(“I am String in Parent”);
}
}

class Child extends Parent{

public void print(Object obj){
System.out.println(“I am Object in Child”);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s