Java Class/Method
- A class can have only public or default(no modifier) access specifier.
- It can be either abstract, final or concrete (normal class).
- It must have the class keyword, and class must be followed by a legal identifier.
- It may optionally extend one parent class. By default, it will extend java.lang.Object.
- It may optionally implement any number of comma-separated interfaces.
- The class's variables and methods are declared within a set of curly braces
{}
. - Each .java source file may contain only one public class. A source file may contain any number of default visible classes.
- Finally, the source file name must match the public class name and it must have a .java suffix.
How a class is initialized in java
class is initialized in Java when an instance of class is created using either new operator or using reflection using
class.forName(). A class is also said to be initialized when a static method of Class is invoked or a static filed is assigned
How to make a copy of an entire Java object with its state
Make that class implement Cloneable interface and call clone() method on its object.clone() method is defined in Object class which is the parent of all java class by default.
Java Method:
In java when you pass a primitive type to a method it is pass by value
when you pass an object of any type to a method it is passed as reference