Ticker

6/recent/ticker-posts

Java (Class)

OOPS CONCEPTS IN JAVA

The object oriented programming technique is used to provides solution to the real world problems with the the help of different types algorithms based on real world situation. 


It uses the real world approach to solve a problem. So object oriented programming technique offers a better and easy way to develop programs as compare than procedural oriented programming languages such as C, ALGOL, PASCAL etc.

Java is an object oriented programming language which supports different object oriented programming concepts like: Class, Object, Inheritance, Abstraction, Encapsulation and Polymorphism.




JAVA CLASS
In Java programming language, everything is encapsulated under classes and class is an user defined data type.
It can be defined as a template that describe the behaviors and states for an object.  

A class defines new data type and once this data type defined, it can be used to create objects of that type (class type).

Object is an instance of class, so we may also call it, as physical existence of a logical template class.

In Java, class keyword is used to to declare a class and a class contain both data and methods (member variables and functions)

A method (member function) is a set of instructions that operate on that data which data defined within its parent class.
The class variables called instance variables and the code and instructions that operates on this data is known as methods.

Thus, the variables and methods, both are are known as class members.


RULES FOR JAVA CLASSES


1. In Java programming language, a class can have only public or default (no modifier) access specifier.

2. It can be either abstract, final or concrete type (normal class).

3. To declare a class, we must have the class keyword, and class name must be followed by a legal identifier.

4. It may optionally extend only one parent class and by default, it extends object class.

5. All the member variables and methods should be declared within a set of curly braces ({ }).

A Java class can contains different types of fields, (Methods, Constructors, and Blocks).



JAVA CLASS SYNTAX
class  class_name 
{
     field;
     method;
}


A SIMPLE CLASS EXAMPLE
Suppose, Student is a class and student's name, roll number, age are its fields and info() is a method. Then class will look like below.

class Student
{
// Declaring variables of  class
int roll_no;
string name;
int age;

// Define the method of class
void info()
{
// This is area where we can write the lines of code
}
}














HOME

Post a Comment

0 Comments