The document discusses different types of inner classes in Java:
1. Member classes are classes declared within another class and have access to all members of the outer class, even private ones. They cannot contain static members.
2. Local classes are declared within a method, constructor or block. They can only access final variables and methods of the outer class.
3. Anonymous classes are defined and instantiated in a single expression without a class name. They are commonly used as event handlers in GUI code.
In this session you will learn:
Inner Classes
For more information, visit this link: https://www.mindsmapped.com/courses/software-development/online-java-training-for-beginners/
In this session you will learn:
Inner Classes
For more information, visit this link: https://www.mindsmapped.com/courses/software-development/online-java-training-for-beginners/
Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality.
Enables you to add new features and functionality to an existing class without modifying the existing class.
What Are Access Modifiers ?
Access modifiers are keywords used to specify the declared accessibility of a member or a type.
Access modifiers support the concept of encapsulation, which promotes the idea of hiding functionality.
Access modifiers allow you to define who does or doesn't have access to certain features.
Types Of Access Modifiers:
public
protected
internal
private
A presentation on the useful feature of Java of providing Nested Classes. A through description of the types of nested classes and the various ways to implement them is stated here.
This is slide presentation that describes inner classes in java and illustrates the concept using demo examples with code shared on both GitHub and dev community.
Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality.
Enables you to add new features and functionality to an existing class without modifying the existing class.
What Are Access Modifiers ?
Access modifiers are keywords used to specify the declared accessibility of a member or a type.
Access modifiers support the concept of encapsulation, which promotes the idea of hiding functionality.
Access modifiers allow you to define who does or doesn't have access to certain features.
Types Of Access Modifiers:
public
protected
internal
private
A presentation on the useful feature of Java of providing Nested Classes. A through description of the types of nested classes and the various ways to implement them is stated here.
This is slide presentation that describes inner classes in java and illustrates the concept using demo examples with code shared on both GitHub and dev community.
It will also show 📺 and it will not have the right now I have a question regarding this matter what I was doing my work with you to see the below link for a long period of time to time and effort and I have been trying to get the job and the way that the people in a different perspective on how the government to be able to get the
Synapse India Reviews About:
Functional/procedural programming:
program is a list of instructions to the computer
Object-oriented programming
program is composed of a collection objects that communicate with each other
This ppt gives information about:
1. OOPs Theory
2. Defining a Class
3. Creating an Object
4. The $this Attribute
5. Creating Constructors
6. Creating Destructors
The static keyword is used in Java mainly for memory management. It is used with variables, methods, blocks and nested class. It is a keyword that is used for share the same variable or method of a given class. This is used for a constant variable or a method that is the same for every instance of a class.
What is Docker and how to make DockerFile.once you create your docker file then we will see how to run and build docker image?
Create simple hello world Node application and then run that application in a docker container.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
2. What is Inner classes
Top-Level (or Outer) Class
You can put a class inside an another class.
A class that contains other classes is a TLC.
Classe that you can write inside another class. Common applications include
iterators and GUIs
Syantax:
class Outer{
class Inner{ }
}
note:
there is no top level static class in java unlike C#
there is only inner static class
3. Nested Class
Nested class:
• Class declared inside another class.
Two kinds of nested classes:
• Member class: class declared at the
member-level of a TLC.
• Local class: class declared inside a
method, constructor, or initializer block
4. Inner Class
Inner class(IC) refers to two special kinds of nested class:
• Non-static member class (member class with no staticmodifier).
• Local class inside a non-static member of a TLC.
Why called inner class?
• Because an object made from the class will containa reference to the
TLC.
• Use TLC.this.memberfrom inside inner class to access member of
TLC.
Restrictions:
• Inner class fields can be static, but then must also be final.
• No staticmethods or other inner classes (same for other members?)
• See language references for even more details
5. Handy way to think of inner
classes inside a TLC
At the member level:
- just like a variable or method.
- called member class.
At the statement level:
- just like a statement in a method
- called local class
At the expression level:
- just like an expression
- called anonymous class
6. Member Class (Member Level)
Rules
Structure:
public class OuterClass{
tlc_members
public class InnerClass{
mc_members
}
}
When to use?
• The inner class generates objects used specifically by TLC.
• The inner class is associated with, or “connected to,” the TLC
7. How does visibility work?
• The inner class can be public, private, protected,
or package.
• Instances of the inner class type have
access to all members of the outer class
(including private and static members).
Some restrictions:
• Cannot have same name as TLC or package (not
that you would want to!).
• Cannot contain static members; can have static
finalfields (constants).
8. How do you use a member
class?
OuterClass oref = new OuterClass();
OuterClass.InnerClass iref = oref.new
InnerClass()
iref.doSomething();
new OuterClass().new InnerClass();
• Not valid:
InnerClass iref = new InnerClass();
iref.doSomething();
9. Internal references with this:
• Inside inner class, the this refers to current
instance of the inner class.
• To get to current instance of TLC, save the
TLC’s this as field in the TLC or
simply use TLC.this.
10. public class MemberClass {
public static void main(String[] args) {
// one way:
OC a = new OC();
OC.IC b = a.new IC();
b.print(); // outputs 3
// another way:
new OC().new IC().print(); // outputs 3
}
}
class OC {
private int x = 1;
public class IC {
private int y = 2;
public void print() {System.out.println(x+y);}
}
}
11. Local Classes (Statement Level)
Local class location:
• Statement level declaration.
• Usually written in methods. See also constructors
and initializers.
Scope:
• Local to block.
• Can access all members of the TLC.
• Actually, things can get confusing here!
- An object of local class might persist after
method ends.
- Java does have rules for dealing with the matter
12. More restrictions:
• Cannot be used outside of block.
• No modifiers.
• Enclosing block’s variables must be finalfor local
class to access.
• No static, but can have static final(constants).
• Terminate with a semicolon! The class is
effectively an expression statement.
• Cannot have same name of TLC
13. public class LocalClass {
public static void main(String[] args) {
new OC().print();
}
}
class OC {
public void print() {
final String s = "test: ";
class Point {
private int x;
private int y;
public Point(int x,int y) { this.x=x; this.y=y; }
public String toString() { return s+"("+x+","+y+")"; }
};
System.out.println(new Point(1,2));
} // method print
} //
14. Anonymous Class
Location and structure:
• Defined and created at expressionlevel.
• So, has no name and no modifiers.
Syntax:
new classname( argumentlist) { classbody}
new interfacename( argumentlist) { classbody}
Adapter class:
• Adapter class defines code that another object invokes.
• Common in GUIs and iterators.
Some restrictions:
• No modifiers.
• No static, but can have static final(constants).
• No constructors, but can use initializers for samepurpose! (See Section 1.2.)
When to use?
• Class has very short body.
• Only one instance of class needed.
• Class used right after defined; no need to create new class
15. In example below, we print a Pointagain. But, we cannot say new Point, because we
have not defined a Pointclass. Instead, I use a placeholder, class Object. You will often
find yourself using interface names instead.
public class AnonymousClass {
public static void main(String[] args) {
new OC().print();
}
}
class OC {
public void print() {
final String s = "test: ";
System.out.println(new Object() {
private int x=1;
private int y=2;
public String toString() { return s+"("+x+","+y+")"; }
} );
}
16. Instantiating an Inner class
Instantiating an Inner Class from within Outer
classes
code:
class Outer{!
private int x = 7;!
public void makeInner(){!
Inner x = new Inner();!
x.seeOuter();!
}!
class Inner{!
public void seeOuter(){!
System.out.println(x);!
}!
}!
}!
5
17. Creating an Inner Class from
Outside of the Outer class
You have to have instance of the
Outer-class
– Outer outer = new Outer();
After that, you create the Inner object
– Outer.Inner inner = outer.new Inner() ;
• One Liner:
– Outer.Inner inner = (new Outer()).new
Inner() ;
18. Method-local Inner Classes
Class inside a method
• Can be instantiated only within the
method (below the class)
• Can use Outer classes private
members
• Cannot use methods variables!!
– Unless the variable is final...
19. class Outer{!
private int x = 7;!
public void method(){!
final String y = "hi!";!
String z = "hi!";!
class Inner{!
public void seeOuter(){!
System.out.println(x); // works!!
System.out.println(y); // works!
//System.out.println(z); // doesn't work!
}!
}!
Inner object = new Inner();!
object.seeOuter();!
}!
}!