Java Classes and Objects
Java Classes and Objects - Important Points
1. | Which of the following is not a valid Java identifier for a class? |
---|
A. MyClass
B. myClass
C. My_Class
D. 1MyClass
View Answer Discuss Work SpaceAnswer: option d
Explanation:
Java identifiers must start with a letter, underscore, or dollar sign. They cannot start with a number.
2. | Which keyword is used to define a class in Java? |
---|
A. class
B. object
C. void
D. new
View Answer Discuss Work SpaceAnswer: option a
Explanation:
3. | Which keyword is used to create an object in Java? |
---|
A. class
B. object
C. new
D. void
View Answer Discuss Work SpaceAnswer: option c
Explanation:
4. | Which of the following is a constructor in Java? |
---|
A. public void MyClass()
B. public MyClass()
C. public int MyClass()
D. public MyClass(int x)
View Answer Discuss Work SpaceAnswer: option d
Explanation:
5. | Which method is called when an object is created? |
---|
A. constructor
B. main
C. finalize
D. toString
View Answer Discuss Work SpaceAnswer: option a
Explanation: