Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java outer class

class OuterClass {
  int x = 10;

  class InnerClass {
    int y = 5;
  }
}

public class Main {
  public static void main(String[] args) {
    OuterClass myOuter = new OuterClass();
    //OuterClass.InnerClass myInner = new OuterClass.InnerClass();
    OuterClass.InnerClass myInner = myOuter.new InnerClass();
    System.out.println(myInner.y + myOuter.x);
  }
}
Comment

what is outer class in java

1. Can Outer class be static? --> No
	2. Can inner class be static? --> Yes
	3. Can you create an object from the inner class? --> Only if it's static
	4. Can we have main method in inner class ? --> Only if it's static
	5. Inner class can only be extended if it's static.
Comment

inner and outer class in java

1. Can Outer class be static? --> No
2. Can inner class be static? --> Yes
3. Can you create an object from the inner class? --> Only if it's static
4. Can we have main method in inner class ? --> Only if it's static
5. Inner class can only be extended if it's static.
Comment

java outer class


public OuterClass getOuter() {
    return OuterClass.this;
}

Comment

PREVIOUS NEXT
Code Example
Java :: android foreground services set auto cancel not working 
Java :: Design a class ‘Complex ‘with data members for real and imaginary part. Provide default and Parameterized constructors. Write a program to perform arithmetic operations of two complex numbers. 
Java :: remove tableview separator lines in javafx 
Java :: java method parameters 
Java :: constructor 
Java :: android studio clock bar change color programmatically 
Java :: java fields 
Java :: int to char java 
Java :: initialize mocks 
Java :: get max of array java 
Java :: declaring variables views in java android 
Java :: how to pass a float between activities in android studio 
Java :: how to delete an element from an array in java data structure 
Java :: example of HashSet 
Java :: afficher matrice java 
Java :: how to create Java ArrayList 
Java :: how to remove scroll pane border 
Java :: how to run few methods of class after mockStatic 
Java :: How to perform an iterative inorder traversal through a binary search tree, in Java? 
Java :: foreach skip to next java 
Java :: how to get the memory location of an object in java 
Java :: what is a cache-less reload 
Java :: java set font 
Java :: Java comment vérifier une égalité de String 
Java :: install oracle java ubuntu 20.04 
Java :: create thread java 
Java :: how to make a rest api in spring 
Java :: print statement in java, simplest java program, Hello World in Java 
Java :: java.lang.classcastexception: java.lang.string cannot be cast to java.util.arraylist 
Java :: generate objects with for loop java 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =