Sunday, 24 June 2018

TCS Tech Lounge JAVA Final-4

class Base{
            public int varOne = 1000;
            public int varTwo = 2000;
            public int varThree;
            void display(){
                       
            }
}
class Derived extends Base{
            public int varThree = 10;
            void display(){
                        System.out.println("varOne:"+varOne);
            }
            void disp(){
                        int varThree = 100;
                        System.out.println("varTwo:"+varTwo);
                        System.out.println("varThree:"+varThree);
                        System.out.println("varThree:"+super.Three);
            }
}
class Demo{
            public static void main(String s[]){
                        Derived ob1 = new Derived();
                        ob1.display();
                        ob1.disp();
            }
}

Ans: ( b ) varone: 1000varTwo: 2000varThree:100varThree:0


Value return on reaching end of file in Writer class?
Ans: -1

Which of the following statements about array is syntactically wrong? Assume that in the options, datatype is any valid datatype in java
Ans: datatype p[5];

What command is used to remove the directory?
Ans: rmdir

TRIM function in oracle will trim off unwanted characters from both sides of string.
Ans: TRUE.





Which of he following is not true about the database objects?
Ans: Views give alternative names to objects.


The method forward(request,response) will
Ans: Return back to the same method from where the forward was invoked


Which method returns a string containing the unique session id?
Ans: getId()


Which of these classes is used for input operation when working with bytes?
Ans: InputStream


Which of the following is true?
Ans: all of the above
a.    Enum in java is a data type
b.    Enum can have fields, constructors and methods
c.    Enum may implement many interfaces but cannot extend any class because it internally extends Enum class



Which of the following is statements are true?
Read(byte[] b)



What is the exception thrown by write() of DataOutputStream class?
Ans: IOException


public class Sample{
            public static void main(String args[]){
            Employee[] e1=new Employee[10];
            Employee emp = new Employee(1,"A");
            System.out.println(e1[0].id);
           
            }          
}
class Employee{
            int id;
            String name;
            Employee(int i, String s)
            {
                        id=i;
                        name=s;
            }
}

Ans: Runtime Error

The expected signature of the main method is public static void main(). What happens if we make a mistake and forget to put the static void keyword? Assume that we are executing using command prompt?
Ans: The JVM fails at runtime with NoSuchMethodError


1.      Which interface does DataInputStream implements?
Ans: DataInput

3. Will this code compile?

class Demo
{
Demo(char status)
{
System.out.println("Parameterized constructor");
}
public static void main(String args[])
{
Demo ob=new Demo('A');
}
}
Ans: This code will compile as the default constructor is not used in main()

4. Which method is used to print the description of the exception?

Ans: printStackTrace()

1 comment:

  1. Thanks for sharing this informative content , Great work
    Creative Thinking for creating an impact!
    Product Thinking Community introduces PT Labs powered by Leanpitch
    Product thinking conference

    ReplyDelete