Skip to content

ImSreyas/OOP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OOP

Repo for Object Oriented Programming lab (sem-2)

1) Normal nested classes

class OuterClass {
    class InnerClass {
        void innerDisplay() {
            System.out.println("Message from inner class");
        }
    }
    
    void display() {
        System.out.println("Message from outer class");
    }
}
public class nestedClass {
    public static void main(String[] args) {
        OuterClass outer = new OuterClass();
        outer.display();
        OuterClass.InnerClass inner = outer.new InnerClass();
        inner.innerDisplay();
    }
}

2) Static nested classes

class OuterClass {
    static class InnerClass {
        void innerDisplay() {
            System.out.println("Message from inner class");
        }
    }
    
    void display() {
        System.out.println("Message from outer class");
    }
}
public class nestedClass {
    public static void main(String[] args) {
        OuterClass outer = new OuterClass();
        outer.display();
        OuterClass.InnerClass inner = new OuterClass.InnerClass();
        inner.innerDisplay();
    }
}

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.6%
  • Other 0.4%