Professional Documents
Culture Documents
OBJECT
ORIENTED
PROGRAMMING
VA S A N T H A K U M A R V
AP/CSE
INNER CLASSES
In Java, it is also possible to nest classes (a class within a class). The purpose of nested classes is
to group classes that belong together, which makes your code more readable and maintainable.
EXAMPLE
class OuterClass public class MyMainClass
{
int x = 10; {
public static void main(String[] args)
class InnerClass {
{ OuterClass myOuter = new OuterClass();
int y = 5; OuterClass.InnerClass myInner = myOuter.new InnerClass();
} System.out.println(myInner.y + myOuter.x);
}
}
}
P R I VA T E I N N E R C L A S S
If you don't want outside objects to access the inner class, declare the class as private.
class Bike9 public static void main(String args[])
{ {
final int speedlimit=90; Bike9 obj=new Bike9();
void run() obj.run();
{ }
speedlimit=400; }
}
FINAL KEYWORD - FINAL METHOD
If you make any method as final, you cannot override it.
class Honda extends Bike
class Bike {
{ void run()
final void run() {
{ System.out.println("running safely with 100kmph");
System.out.println("running"); }
}
} public static void main(String args[])
{
Honda honda= new Honda();
honda.run();
} }
FINAL KEYWORD - FINAL CLASS
If you make any class as final, you cannot extend it.
class Honda extends Bike
final class Bike{} {
void run()
{
System.out.println("running safely with 100kmph");
}
public static void main(String args[])
{
Honda honda= new Honda();
honda.run();
} }
THANK YOU