Primitive Types
bytechar - 16 bit
short
int
long - 64 bit
boolean
float
double
Variables
- variable of primitive types holds value.
- variable of non-primitive types holds reference.
Variable Storage
- Static - static class variables
- Local - primitives
- Dynamic - non-primitives
Parameters
- All the parameters are pass-by-value (since the variables can only be value or reference; for reference it is a copy of the reference).
- There is no direct way change content of a primitive type with parameter (can wrap with array or object).
Class
Accessibility
publicprivate
protected - subclass and class from the same package.
package - member without any leading keyword get default package access.
- no C++ const method
- no ";" after class {}
Inheritance
- no C++ multiple inheritance
- Object is default base class if no base class is specified. Which is the root base class for all classes.
- super is used to initialize superclass.
import Person; public class Student extends Person { private String major; public Student(String name, String major) { super(name); this.major=major; } }
Static and Dynamic Binding
- virtual by default
void a(); //C++==> virtual void a();
Abstract Methods
abstract a(); //C++==> virtual void a()=0;
Call Superclass Version
super.a(); //C++==> baseName::a();
Final Methods
- Cannot be overriden in a subclass
final void a();
Exceptions
- Java exception class must be a subclass of the java.lang.Exception class (which is a subclass of java.lang.Throwable).
- C++ exception can be of any class.
Features of C++ does not exist in Java
- Preprocessor
- Enumeration Types
- Templates
- Operator Overloading
- Named types (typedef)
- Structs and unions
- const class function member.
No comments:
Post a Comment