menu

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

Discuss Work Space

Answer: 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

Discuss Work Space

Answer: option a

Explanation:

The class keyword is used to define a class in Java.

3. Which keyword is used to create an object in Java?

A. class

B. object

C. new

D. void

Discuss Work Space

Answer: option c

Explanation:

The new keyword is used to create an object in Java.

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)

Discuss Work Space

Answer: option d

Explanation:

Constructors have the same name as the class and no return type. They can take arguments or no arguments.

5. Which method is called when an object is created?

A. constructor

B. main

C. finalize

D. toString

Discuss Work Space

Answer: option a

Explanation:

The constructor method is called when an object is created.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now