CheatSheet For Java Beginners
CheatSheet For Java Beginners
Main class
Prepared by
Mostofa Kamal Sagor
CSE111
class A {
static int c=0;
A () { 2
c++;
}
1
3
}
A a1=new A ();
4 c 5
0
1
6
A a2=new A ();
c
1
2
Static method: calls and occupies only static methods and attributes
Non-Static method: calls and occupies both static and non-static
methods and attributes
Prepared by
Mostofa Kamal Sagor
CSE111
WHERE TO USE?
Prepared by
Mostofa Kamal Sagor
CSE111
super this
Access global variable of the Access global variable of the
class inherited…! class itself…!
Used to call the constructor Used to call the constructor
of Parent class or inherited of the class itself…!
class from the Child class…!
Used to call the methods of Used to call the methods of
the parent class when the the child class when the
methods are overridden in methods are overridden in
the child class and you need the child class and you need
to specify your selection to specify your selection
between the parent and the between the parent and the
child class from the child child class from the child
class…! class…!
Global Local
Variable/Attribute/ Variable/Attribute/
Property Property
Located(initiated) outside Located(initiated) inside
of the methods and every the methods or in the
method gets access to parameters of the methods
those. and only the specific
method itself has access to
those.
Prepared by
Mostofa Kamal Sagor
CSE111
Some Golden Rule
Multiple inheritance
▪ One class cannot have multiple inheritance
▪ One class can be inherited by multiple class (Single in
heritance+ Hierarchical/Level wise inheritance)
D extends C
C extends A
B extends A
B C
Prepared by
Mostofa Kamal Sagor
CSE111
Create instance/object or reference of a class
if
Public or Protected
Prepared by
Mostofa Kamal Sagor