You can’t call non static method or fun inside a static method or function
even it is in a same class.
If u want to call static method from another class to main method u have to
call it using
If u want to call non-static method which is declare within same class or in different class but want
to execute it so u have to make the object of that class – non-static members are also known as
instance member or object members variable / function.
When u declared static method or function within class it first made inside
the memory .
Garbage collector deletes unreferenced variable
There are 4 access specifier – Public , Private , protected , default.
Only inner class can be – Public , Private , protected , default but outer
class can’t be private and protected it can be public or default only.
If u want to access private static variable or fun from one class to another u
can access that variable just by first defining a function and then access that
variable within function remember that fun should be declare inside the class
in which private static member variable or function is declared and after that
u can access that variable just by making obj of that class and then using that
obj you can acees that variable through calling the function which was
declared within that class in which private static member is declared.
Read just above sentence then read this What if u don’t want to create
object but want to access private static member variable or fun u can just
make the fun static and then u don’t need to make obj u can just call the
static fun from one class to another class by using classname.functionname
or classname.variablename.
In java we can’t declare any variable or function outside of the class means u
have to declare method or variable inside the class only.
Java is almost 100% object-oriented programming language.
To make java pure 100% object-oriented programming language
we use wrapper classes.
Wrapper class example:-
CLA (command line arguments)
When you run a Java program, you can pass values (like inputs) directly from
the terminal/command prompt, and Java can use those values in your
program.
• args is an array that stores all the values you pass from the command
line. We can write args as any word like abc , xyz etc any word args is
basically written in books but u can give any name as it is only a
reference variable.
• Each word is stored as a string inside that array.
Printing average using CLA
Package :-
Access Specifier
• Public – accessible outside the class, outside the program (same
pacakage or within the package) , outside the package as well
• Private – accessible only inside the class
• Default – accessible outside the class , outside the program (same
pacakage or within the package) , not accessible outside the package.
• Protected - accessible outside the class, outside the program (same
pacakage or within the package) , outside the package as well but
with limits outside the package u can access the outside of the package
through child class. If u don’t make child class u can’t access outside
from the package.
Powerful – Public > Protected > Default > Private
Constructor is a special type of function which is automatically called when
we make an object of any class we don’t need to call it.
NOTE – we have to make a function name same sa a classname then that
function is called to be constructor.
Constructor function is define just by class name it doesn’t have any return
type like it doesn’t have void too. To initialize value constructor is used.
Constructore hamesha bnta h jb ap compile krte h vo .class me bn jata h
compiler banata h jb ap nhi bnate aur vo jo constructor bnta h vo chlta bhi h
but kuch likha nhi hota to hm logo ko dikhta nhi h but jb hm log contructor
khud se bnate h to compiler nhi bnata means every program me constructor
hota h.
Constructor is of 3 types
Default constructor example
Parametrized Constructor
Copy Constructor –