interface toy{       // implicitly abstract
void color();        // implicitly public abstract
int a=1;                // implicitly public static final
}

public class birdy implements toy {
public void color(){System.out.println("yellow");}
public void eat(){System.out.println("fruits");}

public static void main(String args[]){
birdy b1= new birdy();
toy b2=new birdy();

// toy b3=new toy(); //Error: Interface cannot be instantiated
b1.eat();
b2.color();
}
}

Output:
fruits
yellow

 
 
public class parrot extends bird {
public void makesound() {System.out.println("repeat");}

public static void main(String args[]){
bird p=new parrot(); // Polymorphism
p.makesound(); 

}
}

class bird{
public void makesound(){};
}

Ouput:
repeat
 
 
public class B {

public void add(int a, int b) {}
protected void multiply(int a, int b, float c) {}
public float sum(float a, float b) {return a+b;}

public static void main(String args[]){}
}

class C extends B{


public void add(int a, int b){}
// Overriding (Same method name(add), same argument lists)

public void add(int a, int b, int c){}
// Not an Override (Its a new method).
// Its an Overloaded method(same name, different arguments).
// Overridden method should have same argument lists


public void multiply(int a, int b, float c) {}
// Overriding (Same method name(multiply), same argument lists)


//private void multiply(int a, int b, float c) {}
// Error:Cannot reduce the visibility of the inherited method

public float sum(float a, float b) {return a+b;}
// Overriding (Same method name(sum), same argument lists, same return type)

public float sum(float a, int b) {return a+b;}
// Not an override.
// Its an Overloaded method(same name, different arguments).



//public double sum(float a, int b) {return a+b;}
// Error:Duplicate method sum(float, int).
// Not an override.(Overridden method should have same return type)
// Not an overload.(Cant change only the return type) 
// Overloaded method must have different argument lists.

}

 
 
public class A {

public void add(){ }

public void add(int a, int b){}
//1.Overloading (Same method name(add), different no. of arguments)                         


public void add(int a, int b, float c){}
//2.Overloading (Same method name(add), different no. of arguments)

public void add(String a, String b){}
//3.Overloading(Same method name(add),different argument)

public float sum(float a, float b) { return a+b;}

public float sum(float a, int b) { return a+b;}
//1.Overloading (Same method name (sum),different arguments, same return type)

public int sum(int a, int b) { return a+b;}
//2.Overloading(Same method name(sum),different arguments, different return type)

public double sum(float a, float b,int c) { return a+b;}
//3.Overloading(Same method name (sum),different no. of arguments, different return type)

//public double sum(float a, float b) { return a+b;}
// 4.Error:Duplicate method sum(float, float)
//Not a Valid Overload (Can't change only the return type)

}

 
 
public class super1 {
static_init_constuctr() { System.out.println("super1_construct"); } //5
static { System.out.println("super1_static"); }  //1
{ System.out.println("super1_init"); } //4


public static void main(String args[]) {
sub2 ref =new sub2();
System.out.println("The End"); //10
}
}

class sub1 extends super1{
B(){ System.out.println("sub1_construct"); } //7
static{ System.out.println("sub1_static"); } //2
{ System.out.println("sub1_init"); } //6
}

class sub2 extends sub1{
C(){ System.out.println("sub2_construct"); } //9
static{ System.out.println("sub2_static"); } //3
{ System.out.println("sub2_init"); } //8
}


 
 

Enum Inside

public class enuminside {
enum Color {GREEN(1),BLUE(2), RED(3);
int value;
Color(int value){  
this.value=value;
       }
}
public static void main(String args[]){
enuminside.Color c1= Color.GREEN;  //includes class name
enuminside.Color c2= Color.BLUE;
System.out.println(c1);  
System.out.println(c2.value);
}

}
Output:
GREEN
2


 
 
import java.util.*;
public class array_list {
public static void main(String args[]){


//Array to List
Integer a[]=new Integer[]{1,2,3};
List<Integer> array2list=new ArrayList<Integer>();
array2list=Arrays.asList(a);  
// OR 
// List<Integer> array2list=Arrays.asList(a);
System.out.println(array2list);

//List to Array
List<String> ls=new ArrayList<String>();
ls.add("a");
ls.add("b");
String[] list2array=ls.toArray(new String[ls.size()]);
// OR // String[] list2array=ls.toArray(new String[0]);
System.out.println(Arrays.toString(list2array));

}
}
Output:
[1, 2, 3]
[a, b]