0% found this document useful (0 votes)
4 views

Java Cheatshet New

Uploaded by

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

Java Cheatshet New

Uploaded by

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

CLASSES AND OBJECTS

Class Person name = Ram; Constructor


age = 20; Accessing data members and methods : Using dot(.) operator Constructor:
gender =male; p1.name = Ajay;  Special method
p1.eat();  Same name as class name TYPES
Data name
age  No return type
Members
gender  Invokes when object is Parameterized
Default
Method overloading: created
name = Priya; Person(intx)
methods with same name with different types or Person()
eat() age = 18; {
different numbers of parameters or different return type {
Methods
sleep() gender =female Constructor overloading: }
play() class Person{ }
class Person{
int study_hr;
Person() {age = 20; }
void study() {study_hr = 4; }
Person p1 = new Person(); void study(int x) {study_hr = x; } }
Person(int x) {age = x; } }

Nesting of methods: Final Keyword


function call within another function Usage of ‘this’ keyword :
void study()
{
play();
1 Refers to the current class instance
variable Variable Method Class
}
2 Invoke current class method Prevents
ToTounreferenced
unreferencedan an object
object : : Creates
constant
method Prevent
Inheritance
overriding
•After nulling the reference 3 Invoke current class constructor
Static Members :
1 •object= null; Types of Variables:

• After passing reference of one


4 Can be passed as an argument
during method call
Instance Variables Static Static Static
object to another object
2 • Object1 = object2
Can be passed as an argument
variables Method Class
5 during constructor call Local Variables Access Can be
accessed
•Using an anonymous object Refer to to every
without
class in instance
3 • new class_name
6 Return current class instance
variables from method Static Variables general of the
creating
instance
class of a class

You might also like