•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,515 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,817 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 352 | Replies: 2
![]() |
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
class A{
void process() throws Exception{
throw new Exception();
}
}
public class ExtendTest extends A{
void process(){
System.out.print("ExtendTest");
}
public static void main(String[] args) {
A a = new ExtendTest();
a.process(); //line 1
new ExtendTest().process(); // line 2
}
}
Why does this program gives an unhandled Exception at line 1? Line 1 and Line 2 are using same object.
void process() throws Exception{
throw new Exception();
}
}
public class ExtendTest extends A{
void process(){
System.out.print("ExtendTest");
}
public static void main(String[] args) {
A a = new ExtendTest();
a.process(); //line 1
new ExtendTest().process(); // line 2
}
}
Why does this program gives an unhandled Exception at line 1? Line 1 and Line 2 are using same object.
•
•
Join Date: Aug 2007
Location: Adelaide, South Australia
Posts: 428
Reputation:
Rep Power: 3
Solved Threads: 53
You have assigned the variable a as an object of type A. A's process() method throws an exception. You need to wrap the line in a try/catch block. Let me know if this hasn't helped.
Also, doesn't make sense. I think what you want is
java Syntax (Toggle Plain Text)
a.process();
Also,
java Syntax (Toggle Plain Text)
new ExtendTest().process();
java Syntax (Toggle Plain Text)
ExtendTest et = new ExtendTest(); et.process();
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Database Connectivity in C (C)
- An unhandled exception of type 'System.Net.Sockets.SocketException' error (ASP.NET)
- Unhandled exception in IEXPLORER.EXE (SHDOCVW.DLL): 0xC0000005: Access Violation (Web Browsers)
- Visual C++ program compiles, but won't run (C++)
- Recursive Hash map - unhandled exception help (C)
- How to be Crash Free (C++)
- ADO.NET Specified cast is not valid (ASP.NET)
- loads htm but not aspx (ASP.NET)
- Error when installing some .exe programs (Windows 9x / Me)
- Create Windows Authentication (VB.NET)
Other Threads in the Java Forum
- Previous Thread: I need help sorting dates
- Next Thread: getters&setters


Linear Mode