Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
51 views

CheatSheet For Java Beginners

The document discusses object-oriented programming concepts in Java including class types (normal, abstract, interface, final), class relationships (extending, implementing), constructors, static and non-static methods and attributes, inheritance, polymorphism (method overriding and overloading), and access specifiers (public, private, protected). It provides examples of how to use these concepts and the rules that govern them.

Uploaded by

Samara Chaudhury
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

CheatSheet For Java Beginners

The document discusses object-oriented programming concepts in Java including class types (normal, abstract, interface, final), class relationships (extending, implementing), constructors, static and non-static methods and attributes, inheritance, polymorphism (method overriding and overloading), and access specifiers (public, private, protected). It provides examples of how to use these concepts and the rules that govern them.

Uploaded by

Samara Chaudhury
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CSE111

Normal Abstract Interface Final


Class Class class

CAN CAN CANNOT CANNOT


Normal EXTEND EXTEND EXTEND EXTEND
Class
CANNNOT CANNNOT CAN CANNNOT
IMPLEMENT IMPLEMENT IMPLEMENT IMPLEMENT

CAN CAN CANNOT CANNOT


Abstract EXTEND EXTEND EXTEND EXTEND
Class
CANNNOT CANNNOT CAN CANNNOT
IMPLEMENT IMPLEMENT IMPLEMENT IMPLEMENT

CANNOT CANNOT CAN CANNOT


Interface EXTEND EXTEND EXTEND EXTEND

CANNNOT CANNNOT CANNOT CANNNOT


IMPLEMENT IMPLEMENT IMPLEMENT IMPLEMENT

CAN CAN CANNOT CANNOT


Final EXTEND EXTEND EXTEND EXTEND
class
CANNNOT CANNNOT CAN CANNNOT
IMPLEMENT IMPLEMENT IMPLEMENT IMPLEMENT

Main class

▪ that has the static main method


public static void main (String [] args)

▪ can create instances of only normal and final classes…!

▪ cannot create instances of an abstract of interface 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?

class constructor attribute method


before before before
final
before before
static
before before
abstract
before
interface
In
extends between
In
implements between
At the end
return
before
void
before before before before
public
before before before before
protected
before before before before
private

Method Method Abstract


overload override method
▪ In same class ▪ From child class ▪ Partially
implemented
▪ Same name+ different ▪ Same name+
parameters/ parameters+ ▪ No body “{ }”
parameters’ count/ parameters’ count+
return type return type as parent ▪ Ended with “ ; ”
class’s method

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)

Cyclic inheritance involving→not possible


A extends B
B extends A

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 (normal class or final class or parent class), then


call (): the specific constructor…!

else if (child class), then


call (): default constructor of the immediate parent class…!
call (): the specific constructor of child class…!

else //abstract or interface class


msg (): cannot create instance

Level wise access


A
D extends C
C extends B
B extends A B

Will get The attributes and methods of


C
A A
B A B
C A B C
D A B C D D

if
Public or Protected
Prepared by
Mostofa Kamal Sagor

You might also like