What is local class in java ?
itil service transition training itil service operation training itil service design training itil service strategy training
What is local class in java ?
itil service transition training itil service operation training itil service design training itil service strategy training
Inner classes let you define one class within another.
They provide a type of scoping for your classes since you can make one class a member of another class.
Just as classes have member variables and methods, a class can also have member classes.
class Outer {
/class Inner { }
}// End of class
if you compile it,
%javac Outer.java
you’ll end up with two class files:
Outer.class
Outer$Inner.class
A class i.e. created inside a method is called local inner class in java.
3.11. Local Classes. A local class is declared locally within a block of Java code, rather than as a member of a class. Typically, a local class is defined within a method, but it can also be defined within a static initializer or instance initializer of a class.
Local classes are nothing but the inner classes I.e. the class defined inside another class.
created inside a method is called local inner class in java. If you want to invoke the methods of local inner class, you must instantiate this class inside the method
public class localInner1{
private int data=30;//instance variable
void display(){
class Local{
void msg(){System.out.println(data);}
}
Local l=new Local();
l.msg();
}
public static void main(String args[]){
localInner1 obj=new localInner1();
obj.display();
}
}
CertifyGuide – The Ultimate Source of Certification Exam Preparation Guides
A local class is declared locally within a block of Java code, rather than as a member of a class.
Bierdeckeldruck - Bierglaßuntersetzer | Bierdeckel | Bierdeckel bedrucken | Bierdeckel druck
|
Bookmarks