QuestionQuestion

1) Which method is called internally by Thread start() method?

1. execute()
2. run()
3. launch()
4. main()

2) Number of threads in below java program is public class

ThreadExtended extends Thread {

       public void run() {
                System.out.println("\nThread is running now\n");
       }

       public static void main(String[] args) {

                ThreadExtended threadE = new ThreadExtended();

                threadE.start();
       }
}

1. 0 2. 1 3. 2
4. 3

3 ) Which statements is/are correct
1. On calling Thread start () method a new thread get created.
2. Thread start () method call run () method internally
3. Thread run () method can also be called directly to create thread.
4. All correct

4) Which will contain the body of the thread in Java?
1. Start()
2. Run()
3. Main()
4. Execute()

4) which 3 methods are defined in thread class? a) start()
b) wait()
c) notify()
d) run()
e) sleep()

5) Whats the output of below program?

import java.util.*;    class Arraylist
    {
       public static void main(String args[])
       {
            ArrayList obj = new ArrayList();             obj.add("A");             obj.add("B");             obj.add("C");             obj.add(1, "D");
            System.out.println(obj);
       }
    }

a) [A, B, C, D].
b) [A, D, B, C].
c) [A, D, C].
d) [A, B, C].
e) Compile time error


6) What is the output of this program?
    import java.util.*;    class Output
    {
       public static void main(String args[])
       {
            ArrayList obj = new ArrayList();             obj.add("A");             obj.add(0, "B");
            System.out.println(obj.size());
       }    }

a) 0
b) 1
c) 2
d) Any Garbage Value

7) Write a java program to clone Employee class object.
Employee class should contain eid, name and Address as members.
Note: Address should have houseNum, street, state and country as members.
Employee and Address classes should have has-a relation.

8) Write a java program to print elements from int array using enhanced for loop?

9) Create class Employee and Department.
a.Department has employees.
b.Create couple of objects of both type and add to List
c.Take user input and print all employee in a particular department
d.Take user input as employee id , search in List and print employee detail with department name.
e.Print employee details per department sorted by Emp ID and show number of employee per dept.

Implementation Note: No hard coding.
Take all input from console .
Create at least 4 classes two POJO , one utility class to search , sort and print. and one Main class.
Use meaningful name, package , method name etc.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

1) Which method is called internally by Thread start() method?
1. execute()
2. run()
3. launch()
4. main()

Answer: 2. run()

2) Number of threads in below java program is public class ThreadExtended extends Thread {

       public void run() {
                System.out.println("\nThread is running now\n");
       }

       public static void main(String[] args) {

                ThreadExtended threadE = new ThreadExtended();

                threadE.start();
       }
}
1. 0 2. 1 3. 2
4. 3

Answer:
(3) 2

3 ) Which statements is/are correct
1. On calling Thread start () method a new thread get created.
2. Thread start () method call run () method internally
3. Thread run () method can also be called directly to create thread.
4. All correct
Answer: 2

4) Which will contain the body of the thread in Java?
1. Start()
2. Run()
3. Main()
4. Execute()

Answer: run()


4) which 3 methods are defined in thread class? a) start()
b) wait()
c) notify()
d) run()
e) sleep()

Answer: (a), (d), (e)

5) Whats the output of below program?
import java.util.*;    class Arraylist
    {
       public static void main(String args[])
       {
            ArrayList obj = new ArrayList();             obj.add("A");             obj.add("B");             obj.add("C");             obj.add(1, "D");
            System.out.println(obj);
       }
    }

a) [A, B, C, D].
b) [A, D, B, C].
c) [A, D, C].
d) [A, B, C].
e) Compile time error

Answer: (b) [A, D, B, C]

6) What is the output of this program?
    import java.util.*;    class Output...
$15.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats