You are on page 1of 2

JAVA C++

1. Method bodies must be defined inside Method bodies may be defined inside or outside
the class to which they belong. class to which they belong
2.
No Preprocessors Heavy reliance on preprocessor.

3.
Labels on break & continue No Labels on break & Continue.

4.
Main method can’t return a value. Main method can return a value

5.
No global variables Global variables

6.
Can’t mask identifiers through scope Can mask identifiers through scope

7.
Pure Object Oriented Hybrid between procedural & object oriented.

8.
All Functions are part of a class Can have stand alone functions.

9.
Formal interface specifications No formal interface specification.

10.
No multiple inheritance Multiple inheritance

11.
No operator overloading Operator overloading

12. All methods (except final methods)


Only virtual function are dynamically bound
are dynamically bound
13. Combination of combined and
Only compiled
interpreted.
14.
Automatic Garbage collection No automatic garbage collection

15.
Architecture neutral Architecture Specific

16.
Supports multithreading No multithreading
• Checked Exceptions are those which must be included in a method’s throw
list if that generated one of these exceptions & is not able to handle it itself .e.g.
IOEXCEPTION
• Unchecked exceptions need not be included in any method’s throws list and
are automatically available. Compiler doesn’t check to see if a method handles or
throws these exceptions e.g. CLASSNOTFOUND EXCEPTION,
ILLEGALACESS EXCEPTION.
• Throws clause is used to list the type exception that a method might i.e. if a
method can cause an exception that is doesn’t handle then they must be listed with
throws clause otherwise compile time error will occur.
• Throw is used to throw an exception explicitly. The flow of execution stops
immediately after the throw statement. The nearest enclosing try block is
inspected to see if it has a catch statement that matches the type of the exception.
If it does find a method control is transferred there and if no match is found then
default exception handler halts the programe.

You might also like