Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

How to run a class file?

Following example shows how to run a class file from command prompt using java command.

c:\jdk\demoapp>java First 

Result

The above code sample will produce the following result.

Demo application executed.

How to set destination of the class file?

Following example shows how to set destination of the class file that will be created after compiling a java file using -d option with javac command.

c:> javac demo.java -d c:\myclasses 

Result

The above code sample will produce the following result.

Demo application executed.

How to set destination of the class file?

Following example shows how to debug a java file using =g option with javac command.

c:> javac demo.java -g

Result

The above code sample will produce the following result.

Demo.java will debug.

Inheritance ....cont

What is inherited from the base class?
In principle every member of a base class is inherited by a derived class except:
         Constructor and destructor
         operator=()member
         friends
Although the constructor and destructor of the base class are not inherited, the default constructor and the destructor of the base class are alwyas called when a new object of a derrived class is created and destrroyed.   LEARN MORE>>

Classes and Objects...cont(2)

Array within a Class
Arrays can be used as data members in a class. an Array can be a private or a public data member of the class. If an array is a private data member of the class, then only the member functions of the class can access it. Otherwise if an array is a public data member of the class, it can be accessed directly using objects of the class type. Consider the following class definition:
class myarray
{
int a[20];
public;
void getval(void);
void display(void);
};
Here, the arrray a is declared as a as a private member of the class myarray. It can be accessed only through the member functions of the class like any other private data member . The member function getval() reads the values of elements of the array a and the member function display() prints the values of elements of the array a. LEARN MORE>>

Classes and Objects

Introduction
A class is a fundamental building block of the object oriented programming language C++. Bjarne Stroustup, the originator of C++ language, gave the name "C with classes" to this language initially. The class is the most important feature of C++. It implements OOP concepts and ties them together.
A class is a way to bind data (describing an entity) and its associated functions together. In C++, a class makes a data type that is used to create objects of this same type.
The prerequisites for classes and objects are structures and the functions. A structure provides a way to group data elements and a function organizes program actions into a named entity.
Class Specification
A class specification consists of two parts:
1. Class declaration
2. Class method definition
Declaration of a Class
A class is declared using the class keyword. the syntax of a class declaration is similar to that of a structure.
The general form of a class declaration is : LEARN MORE>>