Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

NAME- Anukul Kumar

1) COMPARE AND CONTRAST THE FOUR ACCESS MODIFIERS?


=>

Access Visibility Accessible Inheritance Example


modifier from
a) public Highest Anywhere Yes public class
Myclass{}
b) protected Subclass Same package Yes protected int
& subclasses x;
c) default Package Same package No int m;
d) private Class Same class No private int x;
only

2) Compare and contrast:

=> a) Types of variables:

Variable Description Declaration Memory Scope


Type Allocation
a) Local Defined Inside method Allocated Limited to the
variable within a block or block when method or
or method method or block
block is
executed
b) Instance Belongs to an Inside a class, Allocated Throughout
variable instance of outside when the class
class methods object is instance
created
c) Static Belongs to the Inside a class, Allocated Throughout
Variable class itself, not declared with when class the class
instances static is loaded
NAME- Anukul Kumar

b) Constructor and its types

Constructor Default Parameterized


Constructor constructor
Definition Special method A constructor A constructor with one
used to with no or more parameters.
initialize parameters.
objects.
Invocation Automatically Automatically Invoked with specific
invoked when invoked when arguments during
an object is an object is object creation.
created. created.
Purpose Initialize object to initialize the to initialize the object
state with object and with the values passed
default values. return it to the by the user as the
calling code arguments while
declaring the object.
Syntax ClassName() ClassName() ClassName(parameters
{} {} ){}
Overloading Can be Cannot be Can be overloaded with
overloaded overloaded different types

3) WHAT DO YOU MEAN BY PACKAGE IN JAVA ?

=> In Java, a package is like a folder or directory that helps organize related
classes and interfaces. It's a way to group similar types of code together, making it
easier to manage and understand large projects. Packages provide a hierarchical
structure, where you can have sub-packages within packages.

You might also like