Need urgent help with these java problems

#-Link-Snipped-#

this is the link please download the file and help me with the answers of as many questions as you can

I may be sounding stupid

But please help me with as many answers

as i have exam tomorrow

It will be very kind of you

Thank you

Sarvesh

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    The questions seem to be very basic and answers can be found in any JAVA book. Instead of asking others to solve it for you, why don't you post your answers and ask others to verify?
  • sookie
    sookie
    Hi ,

    Following are the answers of objective questions in those two exams. Feel free to correct if any is wrong.

    Q1 Which class has implicit instantiation?
    A: String [Not sure]. Even if we don't use new keyword, their object is created on the heap.

    Q2: How method overriding can be prevented?
    A: Marking the method with "final" keyword

    Q3:Which class is immutable?
    A: String

    Q4: If you write System.exit(0); at the end of the try block , will the finally block execute?
    A: No, System.exit(0); terminates the execution of the thread in which it is called.

    Q5: Can a Byte object be cast to a double value?
    A: In Java1.5 onwards, it don't need any casting because of autoboxing but in earlier versions it cannot be casted.

    Q6: Which of the following are legal identifiers?
    a) 2variable ->No, cannot start with a number
    b) variable2 ->Yes
    c) _whatavariable- >Yes
    d)_3_ ->Yes

    7: True/False [Not sure]
    a) Methods cannot be overridden to be more private.
    False. Access level can be more restrictive than the overridden method.
    b) static methods cannot be overloaded .
    False. They are rather called as redefined instead of calling as overloaded.
    c) private methods cannot be overloaded.
    False.
    d) An overloaded method cannot throw exceptions not checked in the base class.
    False. It can throw new checked exceptions

    Q8. What is the base class of all classes?
    A: Object

    Q9: Which package is imported by default?
    A: java.lang

    Q10: What is the size of char primitive datatype in Java?
    A: 16 bits or 2 bytes

    Q11: What happens if you define a static variable within a method of class?
    A: Compile time error -"Illegal start of expression" . They should be marked inside the class as they are shared by the class irrespective of instances.

    Q12: An abstract class can be instantiated?
    A: False. Its purpose is to get extended.

    Q13: Arrays are primitive datatypes?
    A: False. int, char, booleanetc. etc are primitive data-types.

    Q14:A main method can be overload?
    A: True.

    Q15: A class can be declared as static?
    A: True.Nested classes can be declared as static.

    Q16:A method declared inside an Interface can be declared as final?
    A: False. No because they are implicitly "abstract".A method cannot be both "abstract" and "final".

    Q17:An interface implements another interface?
    A: False.An interface extends another interface

    Q18: A class can be defined inside an interface?
    A: True [Not sure]

    Q19: An interface can be defined inside a class?
    A: True [Not sure]

    Q20: To what value is a value of the variable of String type automatially initialized?
    A: null

    Q21: What is the defualt priority of a thread?
    A: 5 ->NORM_PRIORITY

    Q22:What is similarity/differences between Abstract classes and Interfaces?
    A:Similarity: Both cannot be instantiated. Both contains at least one abstract method.
    Difference: Abstract class can define both abstract and non-abstract methods but an interface can have only abstract methods.

    Q23:What is the difference between checked and unchecked exceptions?
    A: Checked exceptions are checked by compiler whether the method handles or throws these exceptions while unchecked exceptions are Runtime exceptions that are not checked at compile time.

    Q24:What is the difference between Multi-threading and multi-processing?
    A:Multi-processing: It is that type of multi-tasking in which several programs(or processes) execute simultaneously.
    Multi-threading: It is that type of multi-processing in which several threads (each a part of a process/program) executes simultaneously.
    Multi-threading can be called as a subset of Multi-processing.

    Q25:What is interpreter and compiler in java?
    A: Compiler in Java is a program that converts Java source code into Java byte codes.
    Interpreter in Java is a program that is a part of JVM and executes Java byte codes generated by Java compiler.

    Q26:What is the benefit of multi-threading?
    A:Multi-threading is used for writing efficient programs that can make maximum use of CPU so that its idle time can be used in optimum way. It is useful in networked environment where many requests are made simultaneously.
  • sookie
    sookie
    Q27: Find out the errors in the following program and correct them.
    public class Test {
    
        float x = y;
        byte b = 51;
        static int y = 10;
    
        void setData() {
            b = b * 2;
        }
    
        public static void main(String[] args) {
            Test.setData();
            return;
            System.out.println("ABC" + x);
            
        }
    }
    
    A: Errors are:
    1. Compile time error are b=b*2; because byte * byte gives int and int cannot be directly assigned to byte without explicit casting.
    2. Compile time error at Test.setData(); and System.out.println("ABC" + x);because setData() method is non-static and non static variables or methods cannot be called in static methods without object reference.
    3. return; should always be last statement. So it should come after System.out.println("ABC" + x);

    Corrected program:
    public class Test {
    
        float x = y;
        byte b = 51;
        static int y = 10;
    
        void setData() {
            b = (byte) (b * 2);
        }
    
        public static void main(String[] args) {
            Test t = new Test();
            t.setData();
            System.out.println("ABC" + t.x);
            return;
        }
    }
    
  • sookie
    sookie
    Q28: Write a program to show the use of import and package statements.
    A: Make two folders in any drive of your system
    a) Name one as "com"
    b) Name other as "org"

    In "org" folder, create a following ImportInHello.java class. Add "package org;" at the top of the file.
    package org;
    public class ImportInHello{
    
    public void printHello(){
    System.out.println("Hello in org package");
    }
    }
    
    Now come to "com" folder,create a class named as "Hello.java" which will import class ImportInHello.java
    package com;
    import org.ImportInHello ;
    
    public class Hello{
    public static void main(String[] args){
    System.out.println("Hello in com package");
    ImportInHello obj = new ImportInHello();
    obj.printHello();
    }
    }
    
    Now compile both the files are run "Hello.java", following output will be shown
    Hello in com package
    Hello in org package
  • Kaustubh Katdare
    Kaustubh Katdare
    Sookie - you rock!
  • Kaustubh Katdare
    Kaustubh Katdare
    @sarveshgupta: Maybe you should take a moment to thank sookie?
  • Sahithi Pallavi
    Sahithi Pallavi
    Good job sookie.




    WINNERS DONT DO DIFFERENT THINGS....THEY DO THINGS DIFFERENTLY....
  • gaurav.bhorkar
    gaurav.bhorkar
    Sookie, you rock !
  • sarveshgupta
    sarveshgupta
    Hey Sookie thanks a lot

    @Biggie : I myself really feel thankful to Sookie Although I was not able to see these before my exam today only I have logged in

    But still really thanks a lot Sookie for taking out your precious time to solve these queries

    It will surely help in future

    Great work
  • Kaustubh Katdare
    Kaustubh Katdare
    I see. The answers were posted within 3 hours of you post.

    How was your test?
  • sookie
    sookie
    Thanks everyone, well I was expecting that by this time someone would have posted the answers of the questions which I left for others. Theoretical questions and too easy to answer. Just because of time consuming I left them at that moment. Later, I will do so.

    Thanks !

You are reading an archived discussion.

Related Posts

Sachin Tendulkar slammed his 44th hundered at Premdasa stadium This was his 8th against Sri Lanka India did a fantastic job led by Tendulkar to set a target of 320...
Hi CEans..A silly and mystery question for you .. If we divide the word Heart it will appear as He+art .Why it was like He+art but not sheart dividing it...
I have a 20" lcd monitor. Of late there is certain visible flickering, which I can't seem to resolve. I have already tried changing the refresh rate but it is...
What are the great engineering accomplishments of the 21st century? So far, I say that they are: 1. Using trees as batteries Electrical circuit runs entirely off power in trees...
I'm damn sure we've lot of CEans who are into poetry. I invite all your original creations in this thread. Mind well: Originals only! Anyone?