[go: up one dir, main page]

0% found this document useful (0 votes)
26 views3 pages

Unit 2 (2marks)

Uploaded by

Bavithra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Unit 2 (2marks)

Uploaded by

Bavithra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Unit 2

Inheritance,packages and interfaces

1. What is meant by Inheritance and what are its advantages?


Inheritance is a relationship among classes, wherein one class
shares the structure or behavior defined in another class. This is called
Single Inheritance. If a class shares the structure or behavior from
multiple classes, then it is called Multiple Inheritance. Inheritance
defines “is-a” hierarchy among classes in which one subclass inherits
from one or more generalized super classes. The advantages of
inheritance are reusability of code and accessibility of variables and
methods of the super class by subclasses.

2. What is an Abstract Class?


Abstract class is a class that has no instances. An abstract class is
written with the expectation that its concrete subclasses will add to its
structure and behavior, typically by implementing its abstract operations.

3. What is an Interface?
Interface is an outside view of a class or object which emphasizes its
abstraction while hiding its structure and secrets of its behavior

4. What is a base class?


Base class is the most generalized class in a class structure. Most
applications have such root classes. In Java, Object is the base class for all
classes.

5. What is reflection API? How are they implemented?


Reflection is the process of introspecting the features and state of a
class at runtime and dynamically manipulate at run time. This is supported
using Reflection API with built-in classes like Class, Method, Fields,
Constructors etc. Example: Using Java Reflection API we can get the class
name, by using the getName method
6.
What is the difference between abstract class and interface?
ABSTRACT CLASS INTERFA
CE
1. Abstract class must have at All the methods declared
least one abstract method and inside an interface are
others may be abstract
concrete or abstract
2. In abstract class, key word Interface we need not use that
abstract keyword
must be used for the methods for the methods.
3. Abstract class must have Interface can’t have subclasses
subclasses

7. Define Package.
To create a package is quite easy: simply include a package command
as the first statement in a Java source file. Any classes declared within that file
will belong to the specified package. The package statement defines a name
space in which classes are stored. If you omit the package statement, the class
names are put into the default package, which has no name.

8. What is object cloning?


It is the process of duplicating an object so that two identical objects
will exist in the memory at the same time.

9.Define method overloading?


Method overloading in java is a feature that allows a class to have
more than one method with the same name, but with different parameters.
Java supports method overloading through two mechanisms: By changing the
number of parameters.

10.Define method overridden?


If subclass (child class) has the same method as declared in the parent
class, it is known as method overriding in Java. In other words, If a subclass
provides the specific implementation of the method that has been declared by one
of its parent class, it is known as method overriding.
11. What is String in Java? Is String is data type?
String in Java is not a primitive data type like int, long or double. String is a
class or in more simple term a user defined type. String is defined in java.lang
package and wrappers its content in a character array. String provides equals()
method to compare two String and provides various other method to operate on
String like toUpperCase() to convert String into upper case, replace() to replace
String contents, substring() to get substring, split() to split long String into
multiple String

12. What is interface and state its use?


Interface is similar to a class which may contain method’s signature only but
not bodies and it is a formal set of method and constant declarations that must
be defined by the class that implements it. Interfaces are useful for: a)
Declaring methods that one or more classes are expected to implement b)
Capturing similarities between unrelated classes without forcing a class
relationship. c) Determining an object’s programming interface without
revealing the actual body of the class.

13. Brief Inner class in Java with its syntax.


Java inner class or nested class is a class which is declared inside the class or
interface.
We use inner classes to logically group classes and interfaces in one place so
that it can be more readable and maintainable.
Additionally, it can access all the members of outer class including private
data members and methods.
Syntax of Inner class
class Java_Outer_class{
//code
class Java_Inner_class{
//code
}
}

You might also like