- To enable assertions on non – system classes use –ea or –enableassertions
- To disable assertions on non – system classes use –da or –disableassertions
- To enable assertions on system classes use –esa or –enablesystemassertions
- To disable assertions on system classes use –dsa or –disablesystemassertions
- Assertions can be selectively enabled for the unnamed package in the current working directory.
- In any method with a non void return type we can’t place an assert statement like
“assert false;” ,it results in compiler error but we can place a
“throw new AssertionError();” in place of a return statement.
- A instance variable can be redeclared within a method ,like for example
class A{
int i=1;
void m(){int i=2;}
}
- A method local variable cannot be redeclared within another block inside a method after declaring it inside the method ,like for example
class A{
void m(){
int i = 10;
for(int i = 1;i<20;i++){//this line causes compiler error
System.out.println(i);
System.out.println(i);
}}}
- If a method local variable can be declared inside a method after declaring it inside a block of code then no compiler sets in ,like for example
class A{
void m(){
for(int i=0;i<10;i++){
System.out.println(i);
}
int i=100;
}}
the above class when compiled doesn’t cause error because the variable ‘i’ is declared inside the method after it is declared inside the for loop.
- A constructor can have the following 4 access levels,
- public
- private
- protected
- default or package access level( no modifier)
→If no constructor is supplied by the programmer then the compiler itself creates a “default constructor” for the class. The default has the following properties
· it takes no argument
· it contains a call to the no-arg constructor of the super class as its first statement.
· it will have the same access level as that of the given class.
- A constructor
· cannot be declared final , static , native , synchronized.
· It can declare any exception in it’s throws clause.
· if any other class extends the given class then that class must include the exception in its throws clause or must include a wider exception in its throws clause.
→ it cannot declare the call to super class constructor in try catch clause.
- An anonymous class doesnot have any constructor.
- initializer blocks cannot throw exceptions.