Important Basic Facts about Java
1. Multiple Inheritance can be achieved with the help of interfaces as they don’t implement any function just give a guidelines for the implementation.
E.g.
interface S{final int a=0;}
interface A extends S{}
interface B extends S{}
interface C extends B,A{
}
class Multiple implements C
{
public static void main(String args[])
{
System.out.println(a);
}
}
Output: 0
2. Parent class always passes its own function to the child with its definition in inheritance. So while re-implementation of any interface already implemented by the parent does not make any compulsion for the child class.
E.g.
interface S{final int a=0; void fun();}
interface A{void fun1();}
interface B extends S,A{void fun2();}
abstract class Abst implements B
{
public void fun(){System.out.println("Abtract");}
}
class last extends Abst implements S
{
public void fun1(){System.out.println("lastfun1");}
public void fun2(){System.out.println("lastfun2");}
}
class MultImp{
public static void main(String args[])
{
last l =new last();
l.fun();l.fun1();l.fun2();
}
}
Output:
Abtract
lastfun1
lastfun2
3. Multiple Inheritance in no way can be implemented in Classes
4. All the functions in Java are virtual by default so always support Run Time Polymorphism.
5. Anonymous Inner Class Advantage: It reduces the code size, and also does not create a separate class file for adapter. Disadvantage: It cannot be reused if required at the later stage.
6. Threads can be created using two methods:
a. Implements Runnable Interface: need object of Thread class
b. Extends Thread Class: The object of extended class itself act as a new Thread.
7. MenuBar have Menus which can have Menuitem, CheckboxMenuItem as well as Menu (which act as submenu).
8. Update is called in Paint whenever it is required to save the previous content intact.
9. Objects are called by reference and Variables are called by value.
10. Autoboxing : when a basic type is converted into a wrapper type.
11. Unboxing : when a Wrapper type is converted into a basic type.
Very Good Amar..
ReplyDeleteSwapnil