COMPILER DESIGN

ADVANCED TOPICS IN COMPILER DESIGN

CODE GENERATION FOR OBJECT ORIENTED LANGUAGES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Static methods cannot be accessed directly from the class level.
A
True
B
False
C
Either A or B
D
None of the above
Explanation: 

Detailed explanation-1: -A static method cannot access a class’s instance variables and instance methods, because a static method can be called even when no objects of the class have been instantiated.

Detailed explanation-2: -Static methods are accessed through the class name, rather than an object of the class.

Detailed explanation-3: -A static method can be called directly from the class, without having to create an instance of the class. A static method can only access static variables; it cannot access instance variables.

Detailed explanation-4: -4. Which of the following statements are incorrect? Explanation: All objects of class share same static variable, when object of a class are declared, all the objects share same copy of static members, no copy of static variables are made.

Detailed explanation-5: -Static methods only have access to other static variables and static methods. Static methods cannot access or change the values of instance variables or the this reference (since there is no calling object for them), and static methods cannot call non-static methods.

There is 1 question to complete.