Class 11

Classes in Java

Composite data types are the data types that are based on primitive data types. They are also known as user-defined data types.

Following are the differences between composite data types and primitive data types:
a) Primitive data types are built-in data types. Composite data types are created by users.
b) The size of primitive data types is fixed. But the size of composite data types is not fixed.
c) Primitive data types are available in all parts of a Java program. Composite data types are available according to their visibility scope.

Objects are created using the new keyword, along with the constructor. The new operator instantiates a class by allocating memory for a new object.

Objects receive their storage space from the heap memory.

The dot (.) operator is used to refer to members of an object.

Access specifiers:
a) private members are accessible only inside their own class.
b) public members can be accessed from anywhere.
c) protected members are accessible inside their own class, subclass and package.
d) default access is known as friendly access or package access, meaning they are accessible inside their own class as well as to classes in the same package.

Scope refers to the region within which a variable is accessible.

Visibility refers to whether we can use a variable from a given place in a program.

Encapsulation means that a single thing encloses several smaller things that are its parts. Java accomplishes encapsulation through appropriate use of visibility modifiers.

A local variable having the same name as that of a global variable (having class scope), hides the global variable.

Local variables are the variables declared inside a method or block.

Global variables are class variables which are available to the entire class.

By admin

I am a Computer Science teacher in one of the renowned schools in India. I teach Java programming language to my students, and I maintain a website

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.