Core Java Descriptive Questions and Answer



1. What do you mean by object and class?


Objects are all around us. Anything can be thought of as an Object. An object is an instance of a class. An Object is a module that has both state and behaviour.
A Class is nothing but a blue print for creating different objects which defines the shape and nature of an object. Class is a term that describes a specification for a collection of objects with common properties. A Class is a Template for an object that defines a new data type.


2. What do you mean by inheritance?
http://www.webschoolbd.com
Inheritance can be defined as the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order. A very important fact to remember is that Java only supports only single inheritance. This means that a class cannot extend more than one class.


3. What do you mean by narrowing and widening? Give an example of them.
Conversion from a number with a smaller range of magnitude ( like int to long or long to float ) is called widening. The goal of widening conversions is to produce no change in the magnitude of the number while preserving as much of the precision as possible. For example, converting the int 2147483647 to float produces 2.14748365e9 or 2,147,483,650. The difference is usually small, but it may be significant.
Conversely, conversion where there is the possibility of losing information about the magnitude of the number ( like long to int or double to long ) is called narrowing. With narrowing conversions, some information may be lost, but the nearest representation is found whenever possible. For example, converting the float 3.0e19 to long yields - 9223372036854775807, a very different number.


4. What do you mean by „super( )‟ and „this( )‟ keyword?

this( ) & super( ) is a keyword.

"this( )" is used to invoke a constructor of a same class, its pointing the same class object. "super( )" is used to invoke a super class constructor and accessing the super class constructor.


5. Write down the difference between overloading and overridden.

Overriding - same method names with same arguments and same return types associated in a class and its subclass.

Overloading
- same method name with different arguments may or may not be same return type written in the same class itself.


6. Where we use abstract and final keyword?
Abstract: abstract keyword can be applied to class, interface and method. class_ Contains unimplemented methods and cannot be instantiated. interface_ All interfaces are abstract. Optional in declarations. method_ No body, only signature. The enclosing class is abstract
Final: final keyword can be applied to variables, method, class and field. class_ can not be sub classed.

method_ Cannot be overridden and dynamically looked up.

field_ Cannot change its value. static final fields are compile-time constants. Variable_ Cannot change its value.




7. Write down the difference between interface and abstract class?

Abstract: When one or more methods of a class are abstract.

When the class is a subclass of an abstract class and does not provide not provide any implementation details or method body to any of the abstract methods.

When a class implements an interface and does not provide implement implementation details or method body to any of the abstract methods.
interface:

An interface is not a class but a collection of abstract methods. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements. A Class uses the implements keyword to implement an interface.

We cannot instantiate an interface. An interface does not contain any constructors and instance fields. The only fields that can appear in an interface must be declared both static and final.

An interface is not extended by a class; it is implemented by a class. An interface can extend multiple interfaces.


8. What is the advantage of package? Write down the default package.

Packages
Package is a folder to organize our classes and interfaces. Package can also contain other packages representing a smaller, more specific grouping of classes.

 Packages are useful to :
1. Organize classes into smaller units so that it is easy to locate.
2. Helps to avoid naming conflicts.
3.Protect our classes, data and methods in a larger way on a class to class basis.
4.Identify our classes with the help of the package names.
5.The classes of default package support the basic language features and the handling of arrays and strings. Classes in this package are always available directly in our programs by default because this package is always automatically loaded with our program. The JDK includes the default package name as java.lang.


9. What do you mean by logical and short circuit operator?
The logical operator is & and the short circuit operator is &&.
When & is used it will evaluate both the expressions regardless of the fact that it finds first expression as FALSE and only then will it give an answer. Whereas if && was used in place of &, after it had evaluated first expression and had found result of first expression as FALSE, it would not have evaluated second expression.


10. Write down the difference between wrapper class and data type?

Java has eight primitive data types: four integer types for whole-valued signed numbers (short, byte, int, long), two floating point types for representing numbers with fractional precision (float, double), one character type for Unicode encoding (char), and one boolean type for representing logical values (boolean).

Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes. They are e.g. Integer, Character and Double etc. It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store objects and not primitive data types. And also the wrapper classes provide many utility methods also. Because of these reasons we need wrapper classes. And since we create instances of these classes we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object.

Web School BD

বাংলাদেশের প্রথম অনলাইন ভিত্তিক ট্রেনিং সেন্টার "Web School BD". ওয়েব স্কুল বিডি : https://www.webschool.com.bd

Post a Comment

আপনার কোন কিছু জানার থাকলে কমেন্টস বক্স এ লিখতে পারেন। আমরা যথাযত চেস্টা করব আপনার সঠিক উত্তর দিতে। ভালো লাগলে ধন্যবাদ দিতে ভুলবেন না। শিক্ষার্থীরা নোট ,সাজেশান্স ও নতুন নতুন ভিডিও সবার আগে পেতে আমাদের Web School BD চ্যানেলটি সাবস্ক্রাইব SUBSCRIBE করতে পারো।
- শুভকামনায় ওয়েব স্কুল বিডি

Previous Post Next Post