sadia zara roll # 5... - Sadia123/Assignment-java GitHub Wiki
# Q#1: What is class in java?
A class, in the content of java , are templates that are used to create objects, and to define data types and methods. Core properties include the data types and methods that may be used by the objects. All class objects should have the basic class properties. Classes are categories, and objects are items within each category. parts of a classes
modifier
class name
keywords
class body
curly brackets{}
Q#2: What is difference b/w local variables and class variables?
there are lot of difference between local and class variables in java.class variables belongs to whole class and local variable varies in scope and value.
A local variable is typically used in a method, and has only local scope. class variables are shared among all instances of a class.
Q#3: What is constructor in java?
constructor in java is a special type of method that is used to initialize the objects. java constructor is invoked at the time of object creation.At constructor the values i.e provides data for the objects that why it is known as constructor.
Rules for the creating java constructor
- constructor name must be same as its class name.
- constructor must have no explicit return type.
Types of java constructor
- default of java constructor
- Parameterized constructor
Q#4: What is getter and setter in java?
the public setX() and getX() methods are the access point of the instance variable of the class.Normally, these are referred as getter and setter. Therefore any class that wants to access the variables should access them through these getter and setter.
Q#5: What are access modifier in java?
java has a numbers of access modifiers to set access levels for classes, variables, methods and constructor.
The four access levels are:
- visible to the package (default)
- visible to the class only (private)
- Visible to the word (public)
- Protected Access modifier
1:Default Access Modifier
default access modifier means we do not explicitly declares an access modifier for a class, field, methods, etc.
2:Private Access Modifier
methods, variables and constructor that are declared private can only be accessed within the declared class modifier.
3:Public Access Modifier
a class, method, constructor, interface, etc declared public can be accessed from any other class belonging to the java universe.
4:Protected Access Modifier
variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected member's class.