Object Oriented Programming:
It is new approach introduced in early 70's to provide data security and
reusability.
The lang that supports following oop's features is called as object oriented
programming lang.
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphsim
Abstraction :
Hiding unnecessary details from end user and provide them with the set of
interfaces to consume the functionality is known as abstraction.
Encapsulation :
Keeping the data and functions together in a single wrapper or unit known as class,
to provide data security.
Inheritance :
Reusing the functionalites of existing class in a new class by establishing parent
child relation between classes is known as inheritance.
Polymorphism :
Behaving in different ways depending upon the input receive is known as
polymorphism.
OR
Whenver the input changes the op also changes.
Class :
1) User defined data type.
2) collection of data and functions
3) they are prototype or design that tell how the object will look like.
[<modifiers>] [abstract/final] class <ClassName>
{
-members
}
here modifiers can be
1) public
2) package (default)
public class Student
{
-members
}
class Person
{
}
Object :
int = 10; //invalid
As int is a Datatype , and datatypes dont consume any
space in the memory. To consume a datatype we must create
its variable.
int x = 10; //valid
As,
Class is also a datatype, so above rule applies to a class also.
It means if we want to use a class we need to create a copy of that class known as
object. Using the object we can consume the members present in the class.
Object syntax:
<Classname> <objname> = new <classname>([ <arg1,arg2,...> ]);
Student objs = new Student();
OR
Student objs = new Student(1);
CLASS Code :
package pack_class;
import java.util.Scanner;
public class Person
{
private int age;
private String name;
public void read()
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter age and name ");
age = scanner.nextInt();
name = scanner.next();
}
public void show()
{
System.out.println("age is " + age);
System.out.println("name is " + name);
}
package pack_class;
public class Program
{
public static void main(String[] args) {
Person person = new Person();
person.read();
person.show();
}
}
TODO:
class Calc
{
private int num1,num2;
public void read()
{
public void add()
{
public void sub()
{
class Program
{
main()
{
}
}
class Rectangle
{
private double lenght,breadth;
public void read()
{
public void area()
{
public void peri()
{
}
}
class Program
{
p s v m(String ...)
{