Resurrection can happen in 'finalize' method which will prevent GC to reclaim the object memory. However this could be done only once. Next time GC will not invoke 'finalize' method before garbage collection.
Overriding methods cannot throw more generic exception than base method.
Which ones are classes and which ones are interfaces?
InputStream, OutputStream
DataInputStream, DataOutputStream
Abstract Class
Interface
An 'inner class' is part of the implementation of its enclosing class (or classes). As such, it has access to the private members of any enclosing class. Top-level nested classes are declared with 'static' keyword.
Top level inner classes can be accessed / instantiated without an instance of the outer class. Can access only static members of outer class. Cannot access instance variables or methods of the enclosing class.
Non-static inner classes which are declared without 'static' keyword cannot exist without enclosing class. Can access all the features (even private) of the enclosing outer class.
Local classes are defined inside a block (could be a method, a constructor, a local block, a static initializer or an instance initializer). Cannot be specified with 'static' modifier.
A class cannot have non-static inner interface. All inner classes except anonymous can be 'abstract' or 'final'.
If both the interface have same variable and the variable is not declared in implementing class, the compiler will throw an ambiguous error.
If both the interface have same variable and the variable is not declared in implementing class, the compiler will throw an ambiguous error.
Member variables are resolved at compile time.
Static Runtime runtime=Runtime.getRuntime();
long start,end;
Object obj;
runtime.gc();
start=runtime.freememory();
obj=new object();
end= Runtime.freememory();
System.out.println('size of obj'�+ (start-end)+ 'bytes'�);
[Note: Since GC can't be enforced in java the result is not always predictable.]
class S1_JBK{
public string S= “ S1”;
public string gets() {
returns S;
}
}
class S2_JBK extend S1_JBK {
public string S = “ S2”;
public string gets() {
return S;
}
}
public class shadow_JBK{
public static void main(String S[]) {
S1_JBK s1 = new S1_JBK();
S2_JBK s2= new S2_JBK();
System.out.println("Print S1 " + s1.s);
System.out.println("Print S1 " + s2.s);
s1=s2;
System.out.println("Print S1 now " + s1.S) ;
System.out.println( "Print s1.gets() now " + s1.gets());
}
}
Yes, we can override variables but variables when overridden shadows the super class variable. Print S1 S1 Print S1 S2 Print S1 now S1 Print S1.gets() now S2.
b. [float f = 100.00/0.0. Float division by zero returns NAN (not a number) instead of exception.]
class S1_JBK {
string S= “ S1”;
public string gets (){
return S;
}
void display () {
System.out.println("Display in S1 " + S);
}
}
class S2_JBK extends S1_JBK{
string S= “ S2”;
void display(){
super.display();
System.out.println("Display in S2 " +S);
}
}
public class shadow2_JBK {
string s =” base”;
public static void main(String s[]) {
S2_JBK s2=new S2_JBK();
S2.display ();
S1_JBK s1=new S1_JBK();
System.out.println("Print S1 " + s1.gets());
System.out.println("Print S2 " + s2.gets());
}
}
Methods access variables only in the context of the class they belong to will be used for base class or super class. If subclass calls super class method, it will access super class variable. Display in S1 S1 Display in S2 S2 Print S1 S1 Print S2 S1
False, as map does not implement collection.
Yes, a class can implement two interfaces which has got methods with same name and signatures.
Yes, the mentioned statement is correct.
Interface cannot be declared 'final' as they are implicitly 'abstract'.
'Finalize' is not implicitly chained. A 'finalize' method in sub-class should call 'finalize' in super class explicitly as its last action for proper functioning. Compilers does not enforce this check.
All methods in an interface are implicitly 'public', 'abstract' but never 'static'.
Volatile can be applied only to variables, not for 'static' or 'final'. Declaring a variable volatile indicates that it might be modified asynchronously, so that thread will get correct value and used in multi processor environment.
All variables in an interface are implicitly static , public and final. They cannot be transient or volatile. A class can shadow the interface variable with its variable while implementing.
Transient variables are not stored as object's persistence state and is not serialized for security. Transient variables may not be final or static. Compilers do not give any errors as static variables and anyways they are not serialized.