30 December 2011

Refer FAQ Questions and Improve Your Java Skills

Refer This Questions and Get the Job...!

1.What is the use of main method?
   Main() method is used to start the execution of the program.
   
2.What is overloading?
    Overloading is nothing but having the same name with different parameters.
   (or) The same function having different functionality.

3.What is overriding?
   Overriding is nothing but having same name and method signature.
   It is between  parent class and child class. Child class will always overrides parent class.

4.What are the access modifiers?
   Public, Private, Protected and Default.

5.What is Method Signature?
   Method signature is nothing but (return type of function + function name + no.of arguments).

6.What are the rules we have to follow in overloading?
   i)No.of parameters must be different.
   ii)The type of parameters must be different
   iii)The order of parameters
   iv) It will not depend on return type.

7.What are the Secondary Access Modifiers?
   Static, abstract, final, transient and volatile.

8.What is Shadowing?
   Declaring the same variables of parent class in the subclass is known as Shadowing.
   Example : super.x;  this.b;
  class ClassName {
    int  a; int  b;
    void setA(int a) {
      a = a; //here, the local variable has closer scope than the instance 
           // variable, so the expression set parameter equal to itself
      this.a = a; // this is the correct way to set the parameter to the 
            //instance variable.
    }
    void setB(int b) {
     this.b = b;
   }
 }
Let's look at another example,
 class ClassName {
    String name = "Instance Var."; 
    void someMethod() { 
       String name ="Local Var."; 
       System.out.println(name);   //Local Var.
       System.out.println(this.name); //Instance Var. 
    } 
  }
9.What are the types of data types in Java?
   byte, short, int, float, long, double, char and Boolean

10.Can we call the non static variables into static methods?
   No, vice versa is also not possible.

You cannot use a non-static variable in a static method. If this is what you are trying to do: 
class ClassName
{
 string someVariable;
 

 static void SomeMethod()
 {
  someVariable = "JavaHari";
 }
}
 You cannot do that. However, you can declare the variable static if you need to, like this: 
class ClassName
{
 static string someVariable;
 
 static void SomeMethod()
 {
  someVariable = "JavaHari";
 }
}
11.What is the  basic difference between the overloading and overriding?
   It is necessary to check the method signature in overloading, whereas
  it is not necessary in overriding. Method overloading between the same class methods and method overriding is between parent class method and child class method.

12.What is java bytecode?
   Bytecode is a highly optimized set of instructions designed to be executed by the java run time system, which is called the Java Virtual Machine (JVM)

13.What is java virtual machine?
   JVM is interpreter for the bytecode.

14.What is Encapsulation?
   Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps the safe from outside interference and misuse.


15.What is Data Abstraction?
   An Abstraction is noting but keeping the data and methods in a single object.

16.What is inheritance?
   Inheritance is the process of getting [Base Class futures in to Derived Class] or [Data members & Methods of one class into another class ] is called Inheritance.
17.What are the types of inheritance?
   a) Single Level inheritance.
   b) Multiple inheritances
   c) Multi level inheritance
   d) Hybrid inheritance.
   e) Hierarchical inheritance.

18.Dose Java supports multiple inheritances?
   No.  But by using inner Interfaces it is possible.

19. What is polymorphism?
   Polymorphism is a feature that the process of representing one from to multiple forms is known as.

20. What is Type Costing?
   The conversion of one data type to another data type is known as
   Type Costing. It is possible in higher data type to lower. 

21. What is the range and width of long?
   Range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and the width is 64.

22. What is the range and width of int?
   Range is -2,147,483,648 to  2,147,483,647 and width is 32.

23. What is the range and width of  short?
   Range is -32,768 to 32,767 and width is 16.

24. What is the range and width of byte?
   Range is -128 to 127 and width is 8.

25.  What is the declaration of an Array?
   int  Array[] = new int [5];

26. What is a class?
The process of binding data members and the associated methods in a single unit is known as.  
[OR]A class is a template for an object.

27. What is an Object?
   Object is instance of a class. 
   Instance is nothing but allocation sufficient memory space to Data members and Methods

28. What are called instance variables?
   The data or variables defined within a class are called instance variables.

29. What is a Constructor?
   Constructor is used to initialize the object. Constructors have no return type, not even void.
   For constructor the class name and method name must be same. 
30. What are the types of Constructors?
   Constructors are divided into 3 types : I) Default 2) Parameterized 3)Copy Constructor[object]

31. What are the types of explicit constructors?
   Default constructors and Parameterized constructors.

32. Where we use the key word 'this'?
   'this' is always a reference to the object on which the method was invoked.

33). Can we get the output using Constructors?
   No, These are used only for assigning values.

33. What is garbage Collection?
   If no reference to an object, that object is assumed to be no longer
   needed, and the memory occupied by the object can be reclaimed.
   This is known as garbage collection.

34. What is finalize method?
   Using finalize method we can define specific actions that will occur
   when an object is just about to be reclaimed by the garbage collector.

35. What is call by value and call by reference?
   When a simple type is passed to a method, it is done by use of call
   by-by-value. Objects are passed call by reference.

36. What is Recursion?
   It is a process of defining something in terms of itself.

37.  What is recursive?
   A method that calls itself is said to be recursive.

38. What is Static?
  Static is the key word, which is used to create a member that can be used by itself, without reference to a specific instance. It is a class level variable. It is illegal to refer to any instance variables inside of a static method.

39. Can we refer instance variables inside of a static method?
   No. We can't.
40.What is final?
   The final prevents its contents from being modified.

41.What is an inner class?
Inner class is a class, which is, defined in side another class.

42. What is an anonymous class?
Anonymous class is a class, which don't have any name.

43. What is super?
Super is used to get the properties of the previous class.

44. What is Dynamic Method Dispatch?
Dynamic method dispatch is the mechanism by which a call to an overridden
function is resolved at run time, rather than at compile time.

45. What is an abstract class?
Restriction of data is called Abstract. We can't create the instance.
These are virtual classes. It is same as interface but we can implement the methods.
 
46. What is wrapper class?
Wrapper classes are used to represent the primitive data types as objects.

47. Which key word is used to prevent Overriding?
Final

48. What is a package?
A package statement defines a name space in which classes are stored.

49. What is an interface?
It is a task for specific contract. It does not actually define
any implementations. It is not at all a class. It won't allow constructors.

50. What is public?
If we declare it as a public, classes, subclasses within the package
and outside the package, can access it.       

0 comments:

Popular Posts


www.Java2Hari.blogspot.com. Powered by Blogger.

 
Design by Java2Hari | Bloggerized by Free Blogger Templates | Free Downloads