How to use nested class in Java?

0 votes
Can someone help me understand the use-case of Nested Class in Java? Thank you in advance.
Mar 1, 2019 in Java by Nishita
39 views

1 answer to this question.

0 votes

This program will help you understand the working of function and nested class in Java.

import java.util.*;

class SecondClass
{
    int demofunction(int n)
    {
           System.out.println("This will print the content inside the function");
           int m = 10;
           return m;
    }
}

class MainClass
{  
    public static void main(String args[])
    {
            int n = 20;
            SecondClass obj= new SecondClass();
            System.out.println("This will print the content of main class" + obj.demofunction(n));
    }
}


answered Mar 3, 2019 by Priyaj
• 57,530 points

Related Questions In Java

0 votes
2 answers

How to break the nested loop in Java?

You can use break with a label for the ...READ MORE

answered Sep 20, 2018 in Java by Sushmita
• 6,890 points
145 views
0 votes
2 answers

When and how to use Super() keyword in Java?

super() is used to call immediate parent. super() can be ...READ MORE

answered Jul 9, 2018 in Java by Sushmita
• 6,890 points
220 views
0 votes
1 answer

How to use pairs or 2-tuples in java?

You can refer the following code: public class ...READ MORE

answered Jun 7, 2018 in Java by Daisy
• 8,090 points
83 views
+1 vote
1 answer

How to tell the Maven to use the latest version of dependency in Java?

If you always want to use the ...READ MORE

answered Jun 26, 2018 in Java by Sushmita
• 6,890 points
4,260 views
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,580 points
114 views
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
108 views
0 votes
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,680 points
730 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
1,377 views
+15 votes
19 answers

How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

answered Feb 7, 2019 in Java by Suresh
• 700 points
129,880 views
+4 votes
1 answer

How to print the individual occurance of elements in Java?

You can use a HashMap to serve ...READ MORE

answered Dec 4, 2018 in Java by Priyaj
• 57,530 points
142 views