answersLogoWhite

0


Best Answer

Yes. There is no specific order in which the compiler expects methods to be present. As long as the method is inside the class it is perfectly fine.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can a method be declared in any order in a class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Are there any difference in the way a class method is defined depending on here it is defined?

Yes, there is a difference in the way a class method is defined depending on where it is declared.


Can a private method be overridden?

No. A method that is declared as private in a class is not inherited by any other class and hence if another class that extends this class declares a method with the same name and signature, it does not mean that this method is overridden. It is an entirely separate entity.


When variables are declared in the body of a method they are know as what?

Local Variables There are two types of variables based on the location of declaration 1. Instance Variables- Declared inside a class, but outside of any method's body. 2. Local Variables- Declared inside a method's body inside a class.


Any method in a super class can be overridden in its subclass?

False.Any method declared as final cannot be overridden by any subclasses.You also cannot technically override a private method. While your subclass can have a method with the same definition as a private method in the superclass, it does not actually override that method.


Difference between Method overloading and method overriding in C plus plus?

Yes. Any base class method that is declared virtual can be overridden by a derived class. Overriding a method that is not declared virtual can still be called, but will not be called polymorphically. That is, if you call the base class method, the base class method will execute, not the override. To call a non-virtual override you must call it explicitly.

Related questions

Can Methods be declared in any order in a class.?

Yes. There is no specific order in which the compiler expects methods to be present. As long as the method is inside the class it is perfectly fine.


Are there any difference in the way a class method is defined depending on here it is defined?

Yes, there is a difference in the way a class method is defined depending on where it is declared.


Can a private method be overridden?

No. A method that is declared as private in a class is not inherited by any other class and hence if another class that extends this class declares a method with the same name and signature, it does not mean that this method is overridden. It is an entirely separate entity.


When variables are declared in the body of a method they are know as what?

Local Variables There are two types of variables based on the location of declaration 1. Instance Variables- Declared inside a class, but outside of any method's body. 2. Local Variables- Declared inside a method's body inside a class.


Can this pointer be used within the concept of the static method?

No. When a method is declared static, it is defined outside of any individual class reference.


What does In public mean?

The keyword public is an access specifier. A variable or a method that is declared public is publicly accessible to any member of the project. Any class or method can freely access other public methods and variables of another class.


What is friend datatype in object-oriented programming?

A friend is any class, class method or function that is declared to be a friend of a class. Friends have private access to the classes that declare them friends.


Any method in a super class can be overridden in its subclass?

False.Any method declared as final cannot be overridden by any subclasses.You also cannot technically override a private method. While your subclass can have a method with the same definition as a private method in the superclass, it does not actually override that method.


Difference between Method overloading and method overriding in C plus plus?

Yes. Any base class method that is declared virtual can be overridden by a derived class. Overriding a method that is not declared virtual can still be called, but will not be called polymorphically. That is, if you call the base class method, the base class method will execute, not the override. To call a non-virtual override you must call it explicitly.


What is object in methods in java?

I guess an object in a method would be any object variable, used within a method. An object variable of course is a variable that is declared as a variable of a certain class type.


What is the scope of any variable?

The Scope of a variable defines the areas of a program where this variable would be visible and can be used. For ex: a. Method variables - are visible only inside the method where they are declared and hence their scope is only the method b. Class variables - are visible inside the class and can be used by any method inside the class and hence their scope is the whole class.


What does 'public static final int' mean?

public: It can be called (method) or accessed (field) from any class in any package.static: It is declared on the class rather than the object. If a method, you do not need an object to call it, it can be called directly on the class. If a field, there is only one variable for the class, not one per object.final: If a method, the method cannot be overridden. If a field, the value cannot be changed (a constant).int: If a method, the return type. If a field, the field type (it can only hold values of type 'int'). int is the primitive integer type.