Languages-Java [3i Infotech Placement]: Sample Questions 31 - 32 of 141

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 31

Edit

Describe in Detail

Essay▾

What is the difference between java and C ++

Explanation

Difference between Java and C ++
JavaC ++
No semicolon.End with a semicolon.
Modifiers can be added to each data field or method individually.Divided into major sections by private, protected and public.
Extends to indicate inheritance from a parent class.Class A, B, C, D to indicate inheritance.
Class contains member function implementation.Member function implementation can be external to class.

Question 32

Appeared in Year: 2004

Question

MCQ▾

A class can be converted to a thread by implementing the interface ________

Choices

Choice (4)

a.

Runnable

b.

Thread

c.

All of the above

d.

Question does not provide sufficient data or is vague

Answer

a.

Explanation

  • A class can be converted to a Thread by implementing the Runnable Interface in the “java. lang” package.
  • To implement Runnable interface, a class needs only to implement a single method called run () .
  • Thread can be created by extending the Thread class also.
  • Since Java does not allow multiple inheritance- a class inheriting from Thread cannot inherit from any other class.
  • So it is always better to create a thread by implementing Runnable interface.
  • To run this implementation class, create a Thread object, pass Runnable implementation class object to its constructor.
  • Call start () method on thread class to start executing run () method.
  • Implementing Runnable interface does not create a Thread object, it only defines an entry point for threads in our object allowing us to pass the object to the Thread (Runnable implementation) constructor.

Developed by: