Programming

OOP vs Structural

Object Oriented Programming

It is a used to construct a program with set of properties and method representing. an object

Structural Programming

It is fully made of functions/modules where all the properties and methods represented in the form of modules.

Static

A static can be used for a variable , methods as well as class. Applying a static to a variable, method or class provides different accessibility. To provide you a little further details

  • Static Variable accessible at the class level without creating any instant of the class object.
  • Static Method accessible at the class level without creating any instant of the class object.
  • Static Class can only be initialized in the class that it is inherited.

Variable

Variables are used to initialize and store values in a program computation. There are two main type of variables in programming

  • Global : – Accessible through out the program.
  • Local : – Accessible only in the scope that the variable is declared

Data Type

It is representing a different data type a variable is about to store in the computation as well a method has to return as an output after a computation. The possible datatype are the following

  • Integer
  • Float
  • Char
  • Boolean
  • String
  • And other’s data types

Methods

Are used to define the kind of operation that the object suppose to do in the program. An object could have more than methods. A method can have the following elements

  • Method Name
  • Parameters
  • Return types
  • Access Modifier

Access Modifiers

Access modifier are used t define the accessibility of any members of the class. The possible access modifier are like public, protected , private.

  • Public – Methods, or data members that are declared as public are accessible from everywhere in the program.
  • Private : – Methods or Data members declared as private are accessible only within the class. Meaning “only visible within the enclosing class”  in which they are declared.
  • Protected : – Method or Data members declared as protected “only visible within the enclosing class and any subclasses”
public class PersonPublic {

    private String firstName;

    public PersonPublic(String fName){
        this.firstName = fName;
    }

    public String getFirstName() {
        return firstName;
    }
}

PersonPublic person = new PersonPublic("Public");
System.out.println(person.getFirstName());

Figure 1.1 : – Public Access Modifiers

public class PersonProtected {

    protected String firstName;

    protected PersonProtected(String fName){
        this.firstName = fName;
    }

    protected String getFirstName() {
        return firstName;
    }
}
 PersonProtected person = new PersonProtected("Protected");
 System.out.println(person.getFirstName());

Figure 1.2 : – Protected Access Modifiers

Scroll to Top