Question

In: Computer Science

Give an example of an inner and outer class. (Java)

Give an example of an inner and outer class. (Java)

Solutions

Expert Solution

In Java when the code is too lengthy or complicated you create nested classes or basically group your classes which makes them easy to understand and maintain.

This nesting has mainly inner and outer classes. Inner class is basically the class which is the member of another class. And the class who has other class as member is the outer class. You can understand this with a example -

class Outerclas {

##class methods and functions.

Class Innerclas {

public void nest() {

System.out.println("its the inner class of nested class method"); } } }

class Main {

public static void main(String[] args) {

Outer.Inner inside = new Outer().new Inner();

inside.nest(); } }

The output of this code will be - its the inner class of nested class method.

From the code you can see that the outerclas is the outer class where as the innerclas is the inside class as it's a member of the outerclas.


Related Solutions

true or false give reason language in java 1.A static inner class can access the instance...
true or false give reason language in java 1.A static inner class can access the instance variables and methods of its outer non-static class 2.executeQuery from statement may return more than one resultset object 3.Connection is java.sql interface that establishes a session with a specific database 4.Writable is an interface in Hadoop that acts as a wrapper class to almost all the primitive data type 5.Text is the wrapper class of string in Hadoop
1. Describe the difference between instance methods and class methods in Java and give an example...
1. Describe the difference between instance methods and class methods in Java and give an example of each. 2. A class variable is visible to and shared by all instances of a class. How would such a variable be used in an application? 3. Describe the difference between abstract classes and concrete classes, giving an example of each. 4. Explain how data are encapsulated and information is hidden in Java? 5. Explain the difference between a class and an interface...
3. Assume an annulus of inner radius r1 and outer radius r2. The inner surface is...
3. Assume an annulus of inner radius r1 and outer radius r2. The inner surface is at T1, the outer surface at T2, T1 > T2. Assume heat transfer between the surfaces by conduction, with a variable conductivity, k = a + bT, develop an expression for the temperature in the material of the annulus.
Complete the redblacktree in Java. Add a public boolean isBlack field to the Node inner class....
Complete the redblacktree in Java. Add a public boolean isBlack field to the Node inner class. Make every Node object have a false isBlack field, all new node is red by default. In the end of the insert method, set the root node of your red black tree to be black. Implement the rotate() and recolor() functions, and create tests for them in a separate class. import java.util.LinkedList; public class BinarySearchTree<T extends Comparable<T>> { protected static class Node<T> { public...
A hollow, conducting sphere with an outer radius of .250 m and an inner radius of...
A hollow, conducting sphere with an outer radius of .250 m and an inner radius of .200 m has a uniform surface charge density of -6.37 muC/me2.When a charge is now introduced at the center of the cavity inside the sphere, the new charge density on the outside of the sphere is -4.46 muC/me2. What is the charge at the center of the cavity?
A potential difference of V0 is maintained between the inner and outer conductor of a coaxial...
A potential difference of V0 is maintained between the inner and outer conductor of a coaxial cable of length L, inner conductor radius a, and outer conductor radius b. (a) Calculate the current through the medium (∈,σ) using the analogy of ?⃗ and ?⃗⃗⃗. (b) Now, assume that V0 = 500 V, L = 50 m, a = 2 cm and b = 6 cm, and the relative permittivity and the conductivity of the medium are ∈?=3 and σ=5 μS/m,...
A short and hollow cylindrical bar, having an outer diameter of 4.00 in and an inner...
A short and hollow cylindrical bar, having an outer diameter of 4.00 in and an inner diameter of 7 in, is subjected to two simultaneous loads - an axial compressive force of 75,100 lb. and a torsional moment of 20,100 lb • in. You are required to create two-dimensional (2D) and three-dimensional (3D) stress elements for two stress states on the outer and inner surfaces of the bar to in-plane and out-of-plane stresses, respectively and then draw the 2D and...
A hollow, conducting sphere with an outer radius of 0.240 m and an inner radius of...
A hollow, conducting sphere with an outer radius of 0.240 m and an inner radius of 0.200 m has a uniform surface charge density of +6.37 × 10−6 C/m2. A charge of -0.400 μC is now introduced into the cavity inside the sphere. What is the new charge density on the outside of the sphere? Express your answer with the appropriate units. Calculate the strength of the electric field just outside the sphere. Express your answer with the appropriate units....
What is the relevance of the outer game and the inner game on your leadership behavior?...
What is the relevance of the outer game and the inner game on your leadership behavior? What points of leverage and strategies are given for increasing motivation and employee satisfaction? What variables affect motivation and satisfaction? Why?
68) As you go from the cortex to the outer medulla and to the inner medulla...
68) As you go from the cortex to the outer medulla and to the inner medulla the interstitial solute concentration_______ Increases Stays about the same Decreases None of these 69) Osmoregulation involves the Homeostasis of the Blood platelets Brain tissue Water and solutes inside the body of an animal Red blood cell number Use the next 5 answer choices for the next seven questions (some questions require you to mark two answer choices on your scantron) A) Antidiuretic hormone (ADH)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT