0% found this document useful (0 votes)
5 views

Anukul Java 4

The document compares and contrasts access modifiers, variable types, and constructors in Java. It discusses the four access modifiers - public, protected, default, and private - and their properties. It also compares local, instance, and static variable types as well as default and parameterized constructors.

Uploaded by

anukulk618
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Anukul Java 4

The document compares and contrasts access modifiers, variable types, and constructors in Java. It discusses the four access modifiers - public, protected, default, and private - and their properties. It also compares local, instance, and static variable types as well as default and parameterized constructors.

Uploaded by

anukulk618
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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