COBOL Tutorial

COBOL Object-Oriented Programming

Progress0 of 0 lessons

Introduction to Object-Oriented Programming in COBOL

Object-oriented programming (OOP) in COBOL was introduced in the COBOL 2002 standard, bringing modern programming paradigms to this venerable business language. OOP allows you to organize code using classes, objects, methods, and inheritance, making COBOL programs more modular, reusable, and maintainable.

What is Object-Oriented Programming?

Object-oriented programming is a programming paradigm based on the concept of "objects," which contain data (attributes) and code (methods). In COBOL OOP:

  • Classes are templates that define the structure and behavior of objects
  • Objects are instances of classes, each with its own data
  • Methods are procedures that operate on object data
  • Inheritance allows classes to inherit characteristics from other classes
  • Encapsulation hides implementation details and protects data

OOP in COBOL enables you to create more organized, maintainable code and integrate COBOL applications with modern Java-based systems.

Why Use Object-Oriented COBOL?

Object-oriented COBOL offers several advantages:

  • Code Reusability: Classes can be reused across multiple programs
  • Modularity: Code is organized into logical, self-contained units
  • Maintainability: Changes to one class don't affect others (when properly designed)
  • Java Integration: COBOL classes can interact with Java classes and vice versa
  • Legacy Modernization: Wrap existing procedural COBOL code in classes for modern access
  • Team Development: Different developers can work on different classes independently

Understanding Object-Oriented COBOL (Like You're 5 Years Old)

Imagine you have a cookie cutter (that's a class). The cookie cutter defines the shape of cookies you can make. When you use the cookie cutter to make actual cookies (those are objects), each cookie might have different decorations or flavors, but they all have the same basic shape.

In COBOL, a class is like the cookie cutter - it's a template. When you create an object from a class, it's like making a cookie - you get something real you can use. Each cookie (object) can have its own decorations (data), but they all know how to do the same things (methods) because they came from the same cookie cutter (class).

If you have a special cookie cutter that's based on a regular cookie cutter but adds stars to it, that's like inheritance - the star cookie cutter (subclass) inherits the basic shape from the regular cookie cutter (superclass) but adds something extra!

Core Object-Oriented Concepts in COBOL

1. Classes and Objects

A class is a blueprint that defines what data and methods objects of that class will have. An object (also called an instance) is a specific realization of a class - it has actual data values and can execute methods.

Think of a class as a cookie recipe and objects as the actual cookies you bake. The recipe (class) tells you what ingredients (data) and steps (methods) you need, but the cookies (objects) are the real things you can eat (use in your program).

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
IDENTIFICATION DIVISION. CLASS-ID. Account AS "Account". ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. CLASS java-lang-Object. DATA DIVISION. WORKING-STORAGE SECTION. OBJECT. DATA DIVISION. WORKING-STORAGE SECTION. 01 account-balance PIC S9(9)V99 COMP-3. 01 account-number PIC X(10). PROCEDURE DIVISION. METHOD-ID. get-balance. PROCEDURE DIVISION RETURNING balance AS FLOAT. MOVE account-balance TO balance GOBACK. END METHOD get-balance. METHOD-ID. deposit. LINKAGE SECTION. 01 amount PIC S9(9)V99 COMP-3. PROCEDURE DIVISION USING amount. ADD amount TO account-balance GOBACK. END METHOD deposit. END OBJECT. END CLASS Account.

This example shows a simple Account class with instance data (account-balance and account-number) and two instance methods (get-balance and deposit). The CLASS-ID paragraph defines the class name. The OBJECT paragraph contains the instance data and methods that belong to each Account object.

2. Instance Data vs Factory Data

Instance data belongs to each individual object. When you create multiple Account objects, each has its own account-balance and account-number. Factory data (also called static data) is shared by all objects of the class - there's only one copy that everyone shares.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
IDENTIFICATION DIVISION. CLASS-ID. BankAccount AS "BankAccount". DATA DIVISION. WORKING-STORAGE SECTION. FACTORY. DATA DIVISION. WORKING-STORAGE SECTION. 01 total-accounts-created PIC 9(9) VALUE ZERO. *> This is shared by ALL bank accounts PROCEDURE DIVISION. METHOD-ID. new. LINKAGE SECTION. 01 account-number PIC X(10). 01 initial-balance PIC S9(9)V99 COMP-3. 01 self OBJECT REFERENCE BankAccount. PROCEDURE DIVISION USING account-number initial-balance RETURNING self. *> Create new account instance INVOKE SUPER "new" RETURNING self *> Increment shared counter ADD 1 TO total-accounts-created GOBACK. END METHOD new. METHOD-ID. get-total-accounts. PROCEDURE DIVISION RETURNING total AS BINARY-LONG. MOVE total-accounts-created TO total GOBACK. END METHOD get-total-accounts. END FACTORY. OBJECT. DATA DIVISION. WORKING-STORAGE SECTION. 01 my-balance PIC S9(9)V99 COMP-3. 01 my-account-number PIC X(10). *> Each account has its own balance and number PROCEDURE DIVISION. *> Instance methods go here END OBJECT. END CLASS BankAccount.

In this example, total-accounts-created is factory data - all BankAccount objects share this one counter. Each object has its own my-balance and my-account-number (instance data). The factory method "new" is used to create new account instances.

3. Methods: Instance and Factory

Instance methods operate on a specific object's data. When you call an instance method, it works with that particular object's instance data. Factory methods (static methods) belong to the class itself and don't need an object instance to be called.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
OBJECT. PROCEDURE DIVISION. *> Instance method - operates on THIS object's data METHOD-ID. withdraw. LINKAGE SECTION. 01 amount PIC S9(9)V99 COMP-3. 01 success PIC X. 88 withdrawal-success VALUE 'Y'. 88 withdrawal-failed VALUE 'N'. PROCEDURE DIVISION USING amount RETURNING success. IF my-balance >= amount THEN SUBTRACT amount FROM my-balance SET withdrawal-success TO TRUE ELSE SET withdrawal-failed TO TRUE END-IF GOBACK. END METHOD withdraw. *> Another instance method METHOD-ID. get-account-info. LINKAGE SECTION. 01 info PIC X(50). PROCEDURE DIVISION RETURNING info. STRING "Account: " my-account-number " Balance: " my-balance DELIMITED BY SIZE INTO info GOBACK. END METHOD get-account-info. END OBJECT.

These instance methods work with the specific object's my-balance and my-account-number. Each Account object can call these methods on itself, and they'll operate on that object's own data.

4. Creating and Using Objects

To use objects in COBOL, you need to create them and store references to them. Object references are declared using USAGE IS OBJECT REFERENCE.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
IDENTIFICATION DIVISION. PROGRAM-ID. AccountTest. DATA DIVISION. WORKING-STORAGE SECTION. 01 account1 OBJECT REFERENCE BankAccount. 01 account2 OBJECT REFERENCE BankAccount. 01 deposit-amount PIC S9(9)V99 COMP-3 VALUE 1000.00. 01 withdraw-amount PIC S9(9)V99 COMP-3 VALUE 250.00. 01 result PIC X. PROCEDURE DIVISION. *> Create first account INVOKE BankAccount "new" USING "ACC001" 500.00 RETURNING account1 *> Create second account INVOKE BankAccount "new" USING "ACC002" 1000.00 RETURNING account2 *> Deposit money into first account INVOKE account1 "deposit" USING deposit-amount *> Withdraw from second account INVOKE account2 "withdraw" USING withdraw-amount RETURNING result IF result = 'Y' THEN DISPLAY "Withdrawal successful" ELSE DISPLAY "Insufficient funds" END-IF STOP RUN.

This program creates two BankAccount objects (account1 and account2), each with different account numbers and initial balances. It then performs operations on each object using the INVOKE statement. Each object maintains its own separate balance.

5. Inheritance

Inheritance allows a subclass (child class) to inherit methods and data from a superclass (parent class). The subclass can add new methods, add new data, and override inherited methods.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
IDENTIFICATION DIVISION. CLASS-ID. SavingsAccount AS "SavingsAccount" INHERITS BankAccount. DATA DIVISION. WORKING-STORAGE SECTION. OBJECT. DATA DIVISION. WORKING-STORAGE SECTION. 01 interest-rate PIC 9V999 VALUE 0.025. 01 minimum-balance PIC S9(9)V99 COMP-3 VALUE 100.00. PROCEDURE DIVISION. *> Override the withdraw method to check minimum balance METHOD-ID. withdraw. LINKAGE SECTION. 01 amount PIC S9(9)V99 COMP-3. 01 success PIC X. 88 withdrawal-success VALUE 'Y'. 88 withdrawal-failed VALUE 'N'. PROCEDURE DIVISION USING amount RETURNING success. *> Check if withdrawal would violate minimum balance IF (my-balance - amount) >= minimum-balance THEN *> Call parent's withdraw method INVOKE SUPER "withdraw" USING amount RETURNING success ELSE SET withdrawal-failed TO TRUE DISPLAY "Cannot withdraw: would violate minimum balance" END-IF GOBACK. END METHOD withdraw. *> New method specific to savings accounts METHOD-ID. calculate-interest. PROCEDURE DIVISION RETURNING interest AS FLOAT. COMPUTE interest = my-balance * interest-rate GOBACK. END METHOD calculate-interest. *> New method to apply interest METHOD-ID. apply-interest. PROCEDURE DIVISION. COMPUTE my-balance = my-balance + (my-balance * interest-rate) GOBACK. END METHOD apply-interest. END OBJECT. END CLASS SavingsAccount.

SavingsAccount inherits from BankAccount, so it automatically has all of BankAccount's methods and data. It overrides the withdraw method to add a minimum balance check, and adds new methods (calculate-interest and apply-interest) specific to savings accounts. The INVOKE SUPER statement calls the parent class's method.

6. Encapsulation

Encapsulation means that instance data is private and can only be accessed through methods. This protects the data and allows you to control how it's accessed and modified.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
OBJECT. DATA DIVISION. WORKING-STORAGE SECTION. *> Private instance data - cannot be accessed directly 01 account-balance PIC S9(9)V99 COMP-3. 01 account-number PIC X(10). PROCEDURE DIVISION. *> Getter method - provides read access METHOD-ID. get-balance. PROCEDURE DIVISION RETURNING balance AS FLOAT. MOVE account-balance TO balance GOBACK. END METHOD get-balance. *> Getter method for account number METHOD-ID. get-account-number. PROCEDURE DIVISION RETURNING acct-num AS PIC X(10). MOVE account-number TO acct-num GOBACK. END METHOD get-account-number. *> Setter method - provides controlled write access METHOD-ID. set-balance. LINKAGE SECTION. 01 new-balance PIC S9(9)V99 COMP-3. PROCEDURE DIVISION USING new-balance. *> Can add validation here IF new-balance >= 0 THEN MOVE new-balance TO account-balance ELSE DISPLAY "Error: Balance cannot be negative" END-IF GOBACK. END METHOD set-balance. END OBJECT.

The account-balance and account-number are private - they can't be accessed directly from outside the class. Instead, you must use the getter methods (get-balance, get-account-number) to read them and the setter method (set-balance) to modify them. The setter method can include validation logic to ensure data integrity.

7. Method Overloading

Method overloading allows you to define multiple methods with the same name but different parameter lists. The compiler determines which method to call based on the arguments provided.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
OBJECT. PROCEDURE DIVISION. *> First version - takes integer amount METHOD-ID. deposit. LINKAGE SECTION. 01 amount-int PIC S9(9). PROCEDURE DIVISION USING amount-int. COMPUTE account-balance = account-balance + amount-int GOBACK. END METHOD deposit. *> Second version - takes decimal amount METHOD-ID. deposit. LINKAGE SECTION. 01 amount-decimal PIC S9(9)V99 COMP-3. PROCEDURE DIVISION USING amount-decimal. ADD amount-decimal TO account-balance GOBACK. END METHOD deposit. *> Third version - takes amount and description METHOD-ID. deposit. LINKAGE SECTION. 01 amount PIC S9(9)V99 COMP-3. 01 description PIC X(50). PROCEDURE DIVISION USING amount description. ADD amount TO account-balance *> Could log the transaction with description DISPLAY "Deposit: " description " Amount: " amount GOBACK. END METHOD deposit. END OBJECT.

All three methods are named "deposit" but have different parameter lists. When you call deposit, the compiler chooses the appropriate version based on what arguments you pass. This provides flexibility and a clean interface.

Java Interoperability

One of the powerful features of COBOL object-oriented programming is its ability to interact with Java classes. This enables COBOL applications to use Java libraries and allows Java applications to use COBOL classes.

Using Java Classes from COBOL

COBOL can create instances of Java classes and invoke Java methods. You declare Java classes in the REPOSITORY paragraph.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
IDENTIFICATION DIVISION. CLASS-ID. CobolJavaBridge AS "CobolJavaBridge". ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. CLASS java-lang-Object CLASS java-util-Date AS "java.util.Date" CLASS java-lang-String AS "java.lang.String". DATA DIVISION. WORKING-STORAGE SECTION. OBJECT. DATA DIVISION. WORKING-STORAGE SECTION. 01 java-date OBJECT REFERENCE java-util-Date. 01 date-string OBJECT REFERENCE java-lang-String. PROCEDURE DIVISION. METHOD-ID. get-current-date-string. PROCEDURE DIVISION RETURNING date-str AS OBJECT REFERENCE. *> Create a Java Date object INVOKE java-util-Date "new" RETURNING java-date *> Call toString() method on the Date object INVOKE java-date "toString" RETURNING date-string *> Return the string MOVE date-string TO date-str GOBACK. END METHOD get-current-date-string. END OBJECT. END CLASS CobolJavaBridge.

This example shows how to use Java's Date class from COBOL. The REPOSITORY paragraph declares the Java classes, and you can then create instances and call methods just like COBOL classes.

Wrapping Procedural COBOL for Java

A common use case is creating wrapper classes that make existing procedural COBOL code accessible from Java applications.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
IDENTIFICATION DIVISION. CLASS-ID. LegacyCobolWrapper AS "LegacyCobolWrapper". DATA DIVISION. WORKING-STORAGE SECTION. FACTORY. PROCEDURE DIVISION. METHOD-ID. call-legacy-program. LINKAGE SECTION. 01 input-data PIC X(100). 01 output-data PIC X(100). PROCEDURE DIVISION USING input-data RETURNING output-data. *> Call existing procedural COBOL program CALL "LEGACY-PROG" USING input-data output-data GOBACK. END METHOD call-legacy-program. END FACTORY. END CLASS LegacyCobolWrapper.

This factory method wraps a call to an existing procedural COBOL program, making it accessible from Java. Java code can now invoke this method to use the legacy COBOL functionality.

Complete Example: Bank Account System

Here's a complete example showing a bank account system with inheritance, encapsulation, and method usage.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
IDENTIFICATION DIVISION. CLASS-ID. Account AS "Account". ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. CLASS java-lang-Object. DATA DIVISION. WORKING-STORAGE SECTION. FACTORY. DATA DIVISION. WORKING-STORAGE SECTION. 01 account-counter PIC 9(9) VALUE ZERO. PROCEDURE DIVISION. METHOD-ID. new. LINKAGE SECTION. 01 acct-num PIC X(10). 01 initial-bal PIC S9(9)V99 COMP-3. 01 self OBJECT REFERENCE Account. PROCEDURE DIVISION USING acct-num initial-bal RETURNING self. INVOKE SUPER "new" RETURNING self ADD 1 TO account-counter INVOKE self "initialize" USING acct-num initial-bal GOBACK. END METHOD new. METHOD-ID. get-account-count. PROCEDURE DIVISION RETURNING count AS BINARY-LONG. MOVE account-counter TO count GOBACK. END METHOD get-account-count. END FACTORY. OBJECT. DATA DIVISION. WORKING-STORAGE SECTION. 01 account-number PIC X(10). 01 balance PIC S9(9)V99 COMP-3. PROCEDURE DIVISION. METHOD-ID. initialize. LINKAGE SECTION. 01 acct-num PIC X(10). 01 initial-bal PIC S9(9)V99 COMP-3. PROCEDURE DIVISION USING acct-num initial-bal. MOVE acct-num TO account-number MOVE initial-bal TO balance GOBACK. END METHOD initialize. METHOD-ID. get-balance. PROCEDURE DIVISION RETURNING bal AS FLOAT. MOVE balance TO bal GOBACK. END METHOD get-balance. METHOD-ID. get-account-number. PROCEDURE DIVISION RETURNING acct-num AS PIC X(10). MOVE account-number TO acct-num GOBACK. END METHOD get-account-number. METHOD-ID. deposit. LINKAGE SECTION. 01 amount PIC S9(9)V99 COMP-3. PROCEDURE DIVISION USING amount. ADD amount TO balance GOBACK. END METHOD deposit. METHOD-ID. withdraw. LINKAGE SECTION. 01 amount PIC S9(9)V99 COMP-3. 01 success PIC X. 88 withdrawal-ok VALUE 'Y'. 88 withdrawal-fail VALUE 'N'. PROCEDURE DIVISION USING amount RETURNING success. IF balance >= amount THEN SUBTRACT amount FROM balance SET withdrawal-ok TO TRUE ELSE SET withdrawal-fail TO TRUE END-IF GOBACK. END METHOD withdraw. END OBJECT. END CLASS Account.

This Account class demonstrates factory data (account-counter), instance data (account-number, balance), factory methods (new, get-account-count), and instance methods (initialize, get-balance, get-account-number, deposit, withdraw). The factory method "new" is used to create new account instances.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
IDENTIFICATION DIVISION. PROGRAM-ID. AccountDemo. DATA DIVISION. WORKING-STORAGE SECTION. 01 my-account OBJECT REFERENCE Account. 01 account-num PIC X(10) VALUE "ACC-001". 01 initial-balance PIC S9(9)V99 COMP-3 VALUE 1000.00. 01 deposit-amt PIC S9(9)V99 COMP-3 VALUE 500.00. 01 withdraw-amt PIC S9(9)V99 COMP-3 VALUE 200.00. 01 current-balance FLOAT. 01 withdraw-result PIC X. 01 total-accounts BINARY-LONG. PROCEDURE DIVISION. *> Create a new account DISPLAY "Creating account..." INVOKE Account "new" USING account-num initial-balance RETURNING my-account *> Get initial balance INVOKE my-account "get-balance" RETURNING current-balance DISPLAY "Initial balance: " current-balance *> Make a deposit DISPLAY "Depositing " deposit-amt INVOKE my-account "deposit" USING deposit-amt *> Get updated balance INVOKE my-account "get-balance" RETURNING current-balance DISPLAY "Balance after deposit: " current-balance *> Make a withdrawal DISPLAY "Withdrawing " withdraw-amt INVOKE my-account "withdraw" USING withdraw-amt RETURNING withdraw-result IF withdraw-result = 'Y' THEN DISPLAY "Withdrawal successful" ELSE DISPLAY "Withdrawal failed - insufficient funds" END-IF *> Get final balance INVOKE my-account "get-balance" RETURNING current-balance DISPLAY "Final balance: " current-balance *> Get total accounts created INVOKE Account "get-account-count" RETURNING total-accounts DISPLAY "Total accounts created: " total-accounts STOP RUN.

This program demonstrates how to use the Account class: creating instances, calling instance methods, and calling factory methods. Each operation works with the specific object's data.

Restrictions and Important Considerations

Important Restrictions

  • COBOL classes cannot contain EXEC SQL statements and cannot use the SQL compiler option
  • COBOL classes cannot contain EXEC SQLIMS statements or use the SQLIMS compiler option
  • COBOL programs using OO syntax for Java interoperability cannot contain EXEC CICS statements and cannot run in CICS
  • The OO COBOL framework is not supported with LP(64) compiler option
  • The OO COBOL framework is not supported with AMODE 64 Java
  • It is recommended to develop and run OO COBOL in z/OS UNIX environment

Best Practices

  • Use meaningful class and method names that clearly describe their purpose
  • Keep classes focused - each class should have a single, well-defined responsibility
  • Use encapsulation - make instance data private and provide getter/setter methods
  • Document your classes - explain what each class does and how to use it
  • Use inheritance wisely - only inherit when there's a true "is-a" relationship
  • Override methods carefully - ensure overridden methods maintain the expected behavior
  • Test thoroughly - OOP introduces new complexity that needs testing
  • Consider performance - object creation and method calls have overhead

Exercises and Practice

Exercise 1: Create a Person Class

Create a Person class with the following:

  • Instance data: first-name, last-name, age, email
  • Getter methods for all instance data
  • Setter methods for all instance data (with validation for age and email)
  • A method to return full name (first-name + last-name)
  • A factory method "new" to create Person instances

Hint: Use STRING to concatenate names. Validate that age is between 0 and 150, and that email contains an "@" symbol.

Exercise 2: Create a Student Subclass

Create a Student class that inherits from Person and adds:

  • Instance data: student-id, gpa (grade point average)
  • A method to calculate letter grade based on GPA
  • A method to check if student is on honor roll (GPA >= 3.5)
  • Override the full-name method to include student-id

Hint: Use EVALUATE for letter grade calculation. Use INVOKE SUPER to call parent's full-name method.

Exercise 3: Create a Library System

Create a Book class and a Library class:

  • Book class: isbn, title, author, available (boolean)
  • Library class: maintains a collection of Book objects
  • Library methods: add-book, remove-book, find-book-by-isbn, list-all-books
  • Use a table (OCCURS) to store book references in Library

Hint: Use OCCURS clause for the book collection. Use SEARCH to find books by ISBN.

Test Your Knowledge

1. What is a class in COBOL object-oriented programming?

  • A data structure that holds variables
  • A template that defines the state and capabilities of objects
  • A subroutine that performs calculations
  • A file that stores program data

2. What is the difference between instance methods and factory methods in COBOL?

  • Instance methods are faster than factory methods
  • Instance methods operate on individual object instances, while factory methods are associated with the class itself
  • Factory methods can only be called once
  • There is no difference

3. What keyword is used to define a COBOL class?

  • CLASS-DEFINITION
  • CLASS-ID
  • OBJECT-CLASS
  • DEFINE-CLASS

4. How do you create an instance of a COBOL class?

  • Using the CREATE statement
  • Using the NEW keyword
  • Using the INVOKE statement with the class factory method
  • Using the ALLOCATE statement

5. What is inheritance in COBOL object-oriented programming?

  • Copying code from one program to another
  • A mechanism where a subclass inherits methods and data from its superclass
  • Sharing memory between programs
  • A way to link programs together

6. What is method overriding in COBOL?

  • Deleting a method from a class
  • Defining a method in a subclass with the same signature as a method in the superclass
  • Calling a method multiple times
  • Renaming a method

7. What is encapsulation in COBOL object-oriented programming?

  • Hiding implementation details and controlling access to data through methods
  • Wrapping code in comments
  • Storing data in files
  • Combining multiple programs

8. Can COBOL classes interact with Java classes?

  • No, COBOL cannot interact with Java
  • Yes, COBOL can create instances of Java classes and invoke Java methods
  • Only in certain operating systems
  • Only with special hardware