Skip to main content

Posts

Showing posts from September, 2016

Inner classes

Inner Classes:- class inside class or interface called inner class or nested class. Advantage of inner classes is grouping multiple classes and interfaces into a single class. Another big advantage of inner class is that inner class can happily access all the data or variables of outer class directly. Types of Nested classes:- There are two types of nested classes static and non-static nested classes. (A)Non –static inner classes:- 1)     Member inner class 2)     Anonymous inner class 3)     Local inner class (B)Static nested class Example1:-Outer.java class Outer { class Inner { void disp() { System.out.println("Hello This is Inner class Method"); } } public static void main(String[]args) { Inner in=new Inner(); in.disp(); } } Output:- C:\JAVATECH>javac Outer.java Outer.java:12: error: non-static variable this cannot be referenced from a static context Inner in=new Inner();          ^ 1 error Example

collection interface in java

Collection :Collection is an interface which is present in java.util package and used for representing a group of individual object as a single entity. Collection interface does not having any direct implementation class, collection having some  direct child interfaces and they are having implementation classes based on some specific data structure and provide  ready made method support for various operations . Child interfaces of Collection are List, Set and Queue…… Collection interface having some common methods are used for every collection objects. No. Method Description 1 public boolean add(Object element) Used to insert an object in this collection. 2 public boolean addAll(Collection c)  Used to insert the specified collection objects in the invoking collection. 3 public boolean remove(Object element) Used to delete an object from collection.