1.What is Collection API ?
Ans: The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.
2.How to define an Abstract class?
Ans: A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.
Example of Abstract class:
abstract class testAbstractClass {
protected String myString;
public String getMyString() {
return myString;
}
public abstract string anyAbstractFunction();
}
3.How to define an Interface in Java ?
Ans: In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.
Emaple of Interface:
public interface sampleInterface {
public void functionOne();
public long CONSTANT_ONE = 1000;
}
4.What is the difference between this() and super()?
Ans: this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.
5.What is the difference between superclass and subclass?
Ans: A super class is a class that is inherited whereas sub class is a class that does the inheriting.
6.What modifiers may be used with top-level class?
Ans: The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.
2.How to define an Abstract class?
Ans: A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.
Example of Abstract class:
abstract class testAbstractClass {
protected String myString;
public String getMyString() {
return myString;
}
public abstract string anyAbstractFunction();
}
3.How to define an Interface in Java ?
Ans: In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.
Emaple of Interface:
public interface sampleInterface {
public void functionOne();
public long CONSTANT_ONE = 1000;
}
4.What is the difference between this() and super()?
Ans: this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.
5.What is the difference between superclass and subclass?
Ans: A super class is a class that is inherited whereas sub class is a class that does the inheriting.
6.What modifiers may be used with top-level class?
Ans: public, abstract and final can be used for top-level class.
7.What is method overloading and method overriding?
Ans: Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.
8.What is difference between overloading and overriding?
Ans: 1. In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.
2. Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.
7.What is method overloading and method overriding?
Ans: Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.
8.What is difference between overloading and overriding?
Ans: 1. In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.
2. Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.
3. In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.
4. Overloading must have different method signatures whereas overriding must have same signature.
9.When we can declare a method as abstract method ?
Ans: When we have to want child class to implement the behavior of the method.
10.Can We call a abstract method from a non abstract method ?
Ans: Yes, We can call a abstract method from a Non abstract method in a Java abstract class
9.When we can declare a method as abstract method ?
Ans: When we have to want child class to implement the behavior of the method.
10.Can We call a abstract method from a non abstract method ?
Ans: Yes, We can call a abstract method from a Non abstract method in a Java abstract class
Previous | Next |
:: Click the links below for similar type Questions and answers ::
0 comments:
Post a Comment