Sample content
This team paper explains the following concepts with examples:
1. Class
2. Objects (instances)
3. Instance Variables (attributes or properties)
4. Interfaces
5. Encapsulation
6. Inheritance
7. Polymorphism.
Class:
A class indicates a category of items, as well as acts as a model for producing this kind of items. A class models an abstraction by defining the characteristics as well as behaviors for the items symbolizing the abstraction. The characteristics of an item of a class are also known as features, as well as are described by fields in Java. A field in a class definition is a variable that can store a value which represents a specific property. The behaviors of an item of a class are also called operations, as well as are described using methods in Java. Fields as well as methods in a class definition are jointly called members. For instance we are thinking about a class CharStack to show the different ideas of object-oriented programming.
//
1. PRG 420 Week 5 Team Paper
Link : http://uopexam.com/product/prg-420-week-5-team-paper/
Sample content
This team paper explains the following concepts with examples:
1. Class
2. Objects (instances)
2. 3. Instance Variables (attributes or properties)
4. Interfaces
5. Encapsulation
6. Inheritance
7. Polymorphism.
Class:
A class indicates a category of items, as well as acts as a model for producing this
kind of items. A class models an abstraction by defining the characteristics as well
as behaviors for the items symbolizing the abstraction. The characteristics of an
item of a class are also known as features, as well as are described by fields in
Java. A field in a class definition is a variable that can store a value which
represents a specific property. The behaviors of an item of a class are also called
operations, as well as are described using methods in Java. Fields as well as
methods in a class definition are jointly called members. For instance we are
thinking about a class CharStack to show the different ideas of object-oriented
programming.
// Source Filename: CharStack.java
public class CharStack { // Class name
// Class Declarations:
// (1) Fields:
private char[] stackArray; // The array implementing the stack.
private int topOfStack; // The top of the stack.
// (2) Constructor:
public CharStack(int n) { stackArray = new char[n]; topOfStack = -1; }
3. // (3) Methods:
public void push(char element) { stackArray[++topOfStack] = element; }
public char pop() { return stackArray[topOfStack--]; }
public char peek() { return stackArray[topOfStack]; }
public boolean isEmpty() { return topOfStack
public boolean isFull() { return topOfStack == stackArray.length – 1; }
}
A class description includes a group of member declarations. In the case of the
class CharStack, it has two fields:
• stackArray, that is an array to hold the elements of the stack (in this instance
characters)
• topOfStack, that denotes the top element of the stack (i.e., index of the last
character stored in the array)
The class CharStack has five techniques which execute the essential operations
on a stack:
• push() pushes a character on to the stack
• pop() takes away as well as returns the top element of the stack
• peek() returns the top element of the stack for examination
• isEmpty() decides if the stack is vacant
• isFull() decides if the stack is complete
The class description also has a method-like declaration with the same name as
the class, (2). These kinds of declarations are known as constructors. As we shall
4. observe, a constructor is carried out when an item is created from the class. But,
the execution details in the instance aren’t essential for the current
discussion.
Objects (instances):
An item is an example of a class. The item is developed using the class as a
model as well as is a solid example of the abstraction that the class shows. An item
should be created prior to it being used in a program. In Java, items are
manipulated through object references (also known as reference values or simply
references). The process of developing items normally involves the following steps:
1. Declaration of a variable to store the object reference.
This involves declaring a reference variable of the suitable class to store the
reference to the item.
// Declaration of two reference variables that will denote
// two distinct objects, namely two stacks of characters, respectively.
CharStack stack1, stack2;
2. Creating an object.
This requires using the new operator along with a call to a constructor, to develop
an example of the class.
// Create two distinct stacks of chars.
stack1 = new CharStack(10); // Stack length: 10 chars
stack2 = new CharStack(5); // Stack length: 5 chars
The new operator returns a reference to a new instance of the CharStack class.
This reference can be allotted to a reference variable of the suitable class.
Each item has a exclusive identity and has its own copy of the fields stated in the
class description. The two stacks, denoted by stack1 and stack2, will have their
own stackArray and topOfStack fields.
5. The aim of the constructor
http://uopexam.com/product/prg-420-week-5-team-paper/