answersLogoWhite

0

📱

Java Programming

The Java programming language was released in 1995 as a core component of the Java platform of Sun Microsystems. It is a general-purpose, class-based, object-oriented language that is widely used in application software and web applications.

5,203 Questions

What is the difference between overloading and overriding methods in object?

Here are some of the most common differences between both of them. If you are working in Java for more than 1 year, you might be familiar with all of them but any way its good revision:

1) First and major difference between Overloading and Overriding is that former occur during compile time while later occur during runtime.

2) Second difference between Overloading and Overriding is that, you can overload method in same class but you can only override method in sub class.

3) Third difference is that you can overload static method in Java but you can not override static method in Java. In fact when you declare same method in Sub Class it's known as method hiding because it hide super class method instead of overriding it.

4) Overloaded methods are bonded using static binding and Type of reference variable is used, while Overridden method are bonded using dynamic bonding based upon actual Object.

5) Rules of Overloading and Overriding is different in Java. In order to overload a method you need to change its method signature but that is not required for overriding any method in Java.

What does Inheritance?

It means the ability to be inherited. Most tangible objects which can be owned can be inherited, that is, passed on to the next generation after the owner's death. Intangible things are less likely to be inheritable. Rank, for example. Your father may be a Colonel, but that doesn't mean that if he dies, you get to be a Colonel too.

This applies also to genetics. If you have blue eyes because your parents do, then blue eyes are inheritable. But if you have your arm amputated, you do not have one-armed children--that is not inheritable. Many scientists study the inheritability of a number of human characteristics.

What is the diff between equality of objects and equality of references that refer to them?

References are equal if they both point to the same object.

o2);

// true because they are meaningfully equal

System.out.println(o1.equals(o2));

}

}

Meaningfully equal is defined by overriding the equals method of class Object.

boolean equals (Object obj) Decides whether two objects are meaningfully equivalent.

What is type wrappers in java?

A wrapper class in the Java programming language is one of eight classes provided in the java.lang package to create objects for the eight primitive types. All of the primitive wrapper classes in Java are immutable. Wrapper classes are used to represent primitive values when an Object is required. The wrapper classes are used extensively with Collection classes in the java.util package and with the classes in the java.lang.reflect reflection package. The Wrapper classes are: 1. Byte 2. Short 3. Integer 4. Long 5. Float 6. Double 7. Character 8. Boolean The Byte, Short, Integer, Long, Float and Double are all subclasses of the Number class. If you notice, the names of these wrapper classes are just the same as their primitive data type with a capitalized first letter. These wrapper classes start with a upper case alphabet while their primitive counterparts start with a lowercase alphabet.

What is the difference between overriding overloading and shadowing as well as hiding while using inheritance?

Overloading has nothing to do with inheritance. Overloading is simply a means by which you can provide two or more different ways to call the same function, according to the number and type of arguments you pass to the function.

Overriding is where a derived method provides a new implementation for a base class method. The override may augment the base class method simply by calling the base class method at any time, thus the new implementation need only cater for any differences between the two implementations.

Hiding occurs when you override a base class method that is also overloaded. All the base class overloads are effectively hidden by the overridden method, making them unavailable to the derived class. You must override each overload in order to make it visible to the derived class.

Ideally, you should only override methods that are declared virtual in the base class. In this way you gain the benefits of polymorphic behaviour: when you implicitly call a base class method, the override will be executed instead, thus ensuring all derived objects exhibit correct behaviour, even without prior knowledge as to what those derivatives may be.

Shadowing is similar to hiding insofar as the override "masks" the base class method. However, shadowing is more concerned with nested code blocks that declare the same variable name within the same namespace, and therefore has nothing whatsoever to do with inheritance. For instance, in the following example, the integer i in the outer code block is shadowed by the integer i in the inner code block. What this means is that the value of i in the outer block is not accessible to the inner block, because the i in the inner block masks it. Although this behaviour can sometimes be desirable, it is best avoided as it can lead to ambiguity about which instance of i you are actually referring to, and makes your code that much harder to follow.

for(int i=0; i<3; ++i )

{

std::cout<<i<<std::endl;

for(int i=0; i<3; ++i)

{

std::cout<<i<<" ";

}

std::cout<<std::endl;

}

Output:

0

0 1 2

1

0 1 2

2

0 1 2

If an array has a 100 elements what is the allowable range of subscripts?

Since arrays in C are zero based, the allowed subscript range is 0 - 99 (gives 100 values). Always remember to subtract 1 from the high range (in this case 100) to get the last subscript maximum value.

What is the difference between classes and interference?

The two are totally unrelated. Classes means categories. It is also used as a programming concept. Interference is a phenomenon that happens when two waves meet.

Write a Java program that ask to input 20 students age in a class and gives the average age of given inputs?

import TerminalIO.*;

public class nn8{

public static void main(String[] args){

KeyboardReader reader=new KeyboardReader();

System.out.println("Enter your ages");

int x,y=0;

x=reader.readInt();

for(int i=1;i<=20;x=i)

y=x+i;

System.out.println("the sum is" +y);

}

}

Is constructor overloading same as method overloading.yes or no. explain?

yes,because in constructor overloading constructor have same and different parameter list.

In method overloading method have same name and different parameter list.

Which of these class is related to all the exceptions that can be caught by using catch?

You can catch all exceptions by catching the superclass Exception.

try {

// Do some wacky stuff

} catch (Exception e) {

System.out.println("I've gone nuts");

e.printStackTrace();

}

Is it true default access modifire?

Default access modifier is package. So when you want a method or object variable to be visible within a package, you don't have to insert an access modifier. For public, private or protected, you need to metion them in your java code.

Static method can be call object?

yes we can call a static method with object

Why do i get 500kbps download if i have 5mb download speeds?

Your ISP measures, and sells, bandwith in megaBITS per second, while web browsers and other software measure file downloads in megaBYTES per second.

Since there are 8 bits per byte, with some overhead for control and error correction, a 5 MegaBITS per second (5Mbs) internet connection _should_ download at about 500 kiloBYTES per second (5KBs).

Capital B for bytes, small b for bits.

If you are downloading files at 500KB/s on a 5Mbs connection, it is working fine.

Just divide the BITS per second of your connection by 10 to get the approximate BYTES per second you should be downloading at.

How does knowledge of programming concepts benefit individuals working in almost any IT position?

It does because if you are working in IT company then the thing which matters is: "How can you save the efforts of other people(Customors) so that they will reward you" You can do this only if you automate the process which individual have to perform manually.This can be done by programming only.

What do you mean by multithreaded program Explain the life cycle of a thread?

Thread exists in several states. A thread just created is in the born state. When the threads start

method is called, it enters the runnable (ready) state. Then the system assigns a processor to the thread.

A thread enters the dead state when its run method completes or terminates for any reason. When a sleep

method is called in a running thread, that thread becomes ready after the designated sleep time expires.

Even if a processor is available, sleeping thread can not use it.

A running thread can enter a blocked state.

How do you import an entire package of class in java?

import package_name.*;

where package_name is your package name.

by using this syntax you can import an entire package.

Why is it called a language when UML is a bunch of diagrams?

... for the same reason sign language is not a just bunch of pictures or gestures.

Sign language uses a system of manual, facial, and other body movements as the means of communication.

UML uses visual elements - icons, lines, arrows, etc - as the means of communication.

What are the benefits of inheritance in java programming?

One of the key benefits of inheritance is to minimize the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organization of code and smaller, simpler compilation units.

Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass