Today i learned about the basics of java programming language.
First i saw about class and objects
Class-A blueprint for creating objects. It can contain methods (functions) and fields (variables).
Objects-An instance of a class. It allows access to the class's members (methods and fields).
class A{
int a;
public void set(int n){
a=n;
}
public int get(){
return a;
}
}
public class Main {
public static void main(String[] args) {
A a=new a();
a.set(5);
System.out.println("a.get());
A a2=new A();
System.out.println(a2.get());
}
}
Command line arguments:
It is used to pass the arguments by the users while executing the program.
Void:The void keyword specifies that a method should not have a return value.
String[] args - here args can be any name like program,java,main,etc.
Static variable can be accessed by objects if the value assigned in the class.
Access specifier:
There are four types of access specifier they are
1.private
2.public
3.default
4.protected
1.private: Accessible only within the class where it is declared.
2.public: Accessible from any other class.
3.default (no modifier): Accessible only within classes in the same package.
4.protected: Accessible within the same package and by subclasses in other packages.