Java: 1. What is the purpose of the package statement, its impact on access modi
ID: 3576931 • Letter: J
Question
Java:
1. What is the purpose of the package statement, its impact on access modifiers, and the “default” package?
2. When the import statement is required?
3. What is the difference between “is-a” and “has-a”?
4. Understand this, super, parent/super/ancestor classes, child/sub/descendant classes?
5. What is polymorphism and how is it implemented in Java?
6. What is a binary file?
7. What is the difference between a BufferedReader and Scanner, when are they used, and how are they instantiated?
8. Why and when would we used the clone method?
9. What is the File class used for?
10. What are overriding and overloading, and what is the difference?
11. What is a method’s heading, its signature, and how do they relate to method overloading?
12. What are streams and how are they used in Java?
13. What is the meaning of each word in the following:
public static void main(String[] args)?
Explanation / Answer
1.
A java package is a way of organizing Java classes into namespaces.It encapsulate a group of classes, interfaces and sub packages.
Its impact on access modifier are as follow:
There are 3 packages that are imported by default for each source file. First, the package with no name. Second, the java.lang package. And third, the current package (the package in which the current file is defined).
2.
import statement is used to import the package(either built-in or user-define) into your java source file.
It is required when we want to utilize / use the method of other classes which is in other package into current package class.
3. Inheritance is an "is-a" relationship where Composition is an "has-a" relationship.
A Composition is done by having an instance/object of class as a field of your class.
In programming this is represented as:
4.
"this" is the reference to object of current class which means that it is used to accesss the member (date member/ member function) of current class.
"super" is the reference to object of parent (super/base) class in inheritance which means that it is used to accesss the member (date member/ member function) of parent(super/base) class.
A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).
5.
Polymorphism is derived from 2 greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms. Polymorphism is the ability of an object to take on many forms and by which we can perform a single action by different ways.There are two types of polymorphism in java: compile time polymorphism and runtime polymorphism.
We can implement polymorphism in java by method overloading and method overriding.
6.
A binary file are computer readable format where the instruction are in binary 0's and 1's.It cannot be read by human and are meant for computer only. The byte code that are generated by java compiler are then converted into binary so that the instruction are read by the computer to perform.
7. BufferedReader and Scanner are both meant for standard input but Scanner are used to read and parse the stream into primitive types and strings whereas BufferedReader can just read and store data without any parsing.
Scanner scan = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in);
)
8.
clone() method is used to create a exact copy of an object. It is required when we want to create a copy of an object then we must use clone() to make it because it is a less processing task.
9. File class represent the files and directories pathnames in abstract manner. This class is used when we want to deal with file like creating a file, reading , deleting, searching, etc...
10.
Overloading is a mechanism where in two method of same class can have the same name but differ in their signature where as Overriding is a mechanism of having same name and signature of method of parent class in subclass.
The difference in overloading and overriding is that in overloading the method name are same but they are differ in signature (the number of parameter/ type of parameter) where as in overriding the name and signature both are same but they are parent and child class.
11.
Method Signature are the parameters and return type.
12.
Stream can be define as sequence of data and there are two kind of stream i.e., Input and Output Stream.
13.
public static void main(String[] args)
public-> access modifier
static-> can be access with reference of class and no object is required
void-> no return type.
main-> method name
String[] args-> method argument arrrays of string
Access Modifier within class within package outside package by subclass only outside package Private y n n n Default y y n n Protected y y y n Public y y y yRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.