answersLogoWhite

0


Best Answer

A class declaration tells the compiler what your class will be called, what data it will contain, and what methods it will have. For example, in Java and C# it looks roughly like this:

class MyClass {

private int x;

private int y;

public MyClass(int px, int py) {

x = px;

y = py;

}

public int sumXY() {

return x + y;

}

}

This declares a class called 'MyClass' with two data elements (or variables), called 'x' and 'y'. They are integers (whole numbers). The class has a constructor method (constructor methods always have the same name as the class, so the constructor method is also called 'MyClass'). You give two numbers to the constructor method, and it fills in the two numbers in the MyClass object with those two numbers.

The class also has another method, called 'sumXY', which returns the sum of the two numbers the object contains.

The 'public' and 'private' are used to determine who can or can't see the variables and methods of your class. If a variable or method is marked 'private', it can only be seen by methods inside the class. If it's marked 'public', other classes can reach inside and look at it or even change it.

Hope this helps.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a class declaration?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is inline declaration?

It is a declaration of java class in method body which called "inner class"


Which one is the compulsory section in a java program?

Class declaration


Who writes the declaration?

Thomas Jefferson wrote the declaration of independance we just learned it in history class.


When do you declare a class as final?

By using the final keyword in the class declaration statement. Ex: public final class Test {...}


How do you prepare declaration of project work class 12th?

by writing


Why am I getting Java unreported exception while compiling my class?

It may be because you are using inheritance and your super class constructor has a throws clause in its declaration. If your super class has a throws clause in its constructor declaration, you must do the same in your child class constructor in order to eliminate this compiler error.


How do you call a member function of one class in another class using friend function?

class B; // forward declaration. class A { private: void myFunction(B b){b.myFunction();} // Calls private method in b. }; class B { friend void A::myFunction(B b); // Friend function declaration. private: void MyFunction(); };


In c plus plus Who tells the compiler that a specific class will be declared later in the program?

A forward declaration. However forward declarations can only be used when the class is used as a pointer or reference prior to its definition, otherwise it must be defined before it is used. class A; // forward declaration class B { A& data; // reference to class that has yet to be defined }; class A {}; // definition


Explain the structure of a java program?

The fundamental structure of any Java programme should look like: [package declarations] [import statements] [class declaration] An example is given below: package abc; import java.lang; class Demo { public static void main(String[] args) { Sytem.out.println("Hello! World"); } } //The file containing this class must be named Demo.java


When is the result declaration in Ideal Indian School year 2012?

result for class 6 2012


Plzzzzz tell you d date of declaration of cbse 10th class for delhi region?

29 may


Retotaling form for class 10th of mp board 2009?

within 21 days after declaration of result.