Questions that I knocked over in an interview

I was asked several answers to questions on java that I had no idea how a solution might use some answers

  • write a method that accepts int, so the method will be

    public void somemethd (int i) {}

    Now, if I = 1, then it should print true, and if I = 2, it should print false but you cannot use any conditional statements and cannot use if or switch

  • how two streams transmit data between each other, for example let let you say that you are launching 2 streams, and you want to make one stream in order to animate the other stream. he paraphrased the question to make it easier, what if I have varible in 1 thread, and I want to send it to another thread, how to do it.

  • What to do if there is a non-stationary method in the base class and you make it a static method in a derived class, you will get the same error as u if you have a static method in the database and you try to make it non-static in the derived class

  • What is overload different from the name for another method? (I think I should have said about the constructor overload, but it just didn’t come to me, there is something else)

  • The syntax is incorrect, but it can be assumed that everything is in order

    
    
    

    class base{

    show(){

    this.mymethod(); }

    mymethod(){ /... } }

    class derived extends base{

    show(){
    
    super.mymethod();
    }
    
    mymethod(){
    /...
    }
    }
    

now when i do the following

and.

base b = new derived();

   b.show(); 

b.

derived d= new base();

   d.show();

with. what if in base n there was no show method

 base b = new derived();

   b.show(); 

e. what if in base n there was no show method

 d = new base (); d.show (); Code>
+3
source share
2 answers

One solution for updated 1)

void printIsOne(int n) {
   System.out.println("?,true,false".split(",")[n]);
}

2) . . : - BlockingQueue.

3) , .

4) . , . , , - , .

5) (: )

+11

, int true, 1 false, true, , swith

, true, 1 false, 0, :

void printValue(int value)
{
    String[] values = { "false", "true" };
    System.out.println(values[value]);
}
+8

Source: https://habr.com/ru/post/1791201/


All Articles