0% found this document useful (0 votes)
4 views2 pages

Java Inheritance and Access Specifiers Guide

The document discusses various concepts of inheritance in Java, including types such as single, multi-level, and hierarchical inheritance, as well as the advantages of inheritance like reusability and extensibility. It also explains access specifiers, the difference between public and protected, and the role of the Scanner class for user input. Additionally, it touches on wrapper classes, primitive vs non-primitive data types, and the default package in Java.

Uploaded by

tikitakam40
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)
4 views2 pages

Java Inheritance and Access Specifiers Guide

The document discusses various concepts of inheritance in Java, including types such as single, multi-level, and hierarchical inheritance, as well as the advantages of inheritance like reusability and extensibility. It also explains access specifiers, the difference between public and protected, and the role of the Scanner class for user input. Additionally, it touches on wrapper classes, primitive vs non-primitive data types, and the default package in Java.

Uploaded by

tikitakam40
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

DAY2: Multiple inheritance is the ability for a class to

inherit behaviours from multiple types. Java


1. Inheritance, 2. Access specifiers,
does not support multiple inheritance of state
3. Data types, 4. Scanner class
(fields/properties) through classes.
QUESTIONS(Theory)
4. Difference between hybrid and hierarchical
1. What is meant by inheritance? inheritance?
Inheritance in Java is the method to create a In hierarchical Inheritance, there is only one
hierarchy between classes by inheriting from base class, and it can have many derived
other classes. classes, but hybrid Inheritance is a
combination of more than one inheritance, it
2. Types of inheritance and explain all types?
can be a combination of single and multiple
In Java, Inheritance means creating new inheritance or multilevel and multiple
classes based on existing ones. A class that inheritance, etc.,
inherits from another class can reuse the
5. Advantages of inheritance?
methods and fields of that class. In addition,
you can add new fields and methods to your Inheritance provides several advantages
current class as well. including reusability, saving time and effort,
data hiding, extensibility, easy
Different Types of Inheritance
understandability, and reliability.
Single Inheritance - a class inherits from only
6. What is the use of access specifier and
one parent class
types?
Multi-level Inheritance - a class inheriting
Access specifier or modifiers is used to set the
from a derived class, creating a chain of
accessibility levels of classes, interfaces,
inheritance.
methods, and member variables with the help
Multiple Inheritance - a class to inherit of these keywords. The four main types of
features and behaviours from more than access modifiers: `public`, `private`,
one parent class. `protected`, and the default access (no
modifier). The `public` modifier allows
Multipath Inheritance - a child class can
elements to be accessible from any other
access methods from more than one parent
class in the application, regardless of the
class, leading to a more flexible design.
package.
Hierarchical Inheritance - allows
7. Difference between public and protected?
different child classes to share
the properties and methods of the same `Public` modifier allows elements to be
parent. accessible from any other class in the
application, regardless of the package.
Hybrid Inheritance - combination of different
inheritance types, like single, multiple, `Private` restricts access to the elements only
and hierarchical, within one structure. within the class they are declared.

3. What is meant by multiple inheritance, why `Protected` allows access within the same
java won't support multiple inheritance? package or in subclasses, which might be in
different packages.
8. What is mean by Wrapper class? 15. What are the different methods available
in Scanner class?
A wrapper class is a class that encapsulates
types, so that those types can be used to nextInt(): Reads integer values.
create object instances and methods in
nextFloat(): Reads float value.
another class that needs those types.
nextDouble(): Reads double value.
9. What is default value of String?
nextBoolean(): Reads boolean value.
The default value of String is Nothing (a null
reference). nextLine(): Reads string value until newline
character ('\n') is encountered.
10. Why String is non primitive datatype?
next(): Reads string value until space or
String is non-primitive because only class can
newline character is encountered.
have methods
16. Scanner class is under which package?
11. What is the difference between primitive
and non primitive datatypes? It is found in the [Link] package.
Primitive data structures are simple and 17. Difference between next() and nextLine()?
predefined types like integers and booleans,
used for basic data storage, whereas non- next() reads input until whitespace is
primitive structures like arrays and lists are encountered.
more complex, designed for organizing nextLine() reads input until a newline
collections of data and enabling advanced character is encountered
data manipulation.

12. What is default package in java?

Default Package doesn't have a name but it is


present by default and thus, it is named the
default package.

[Link] package and a no-name package

13. What is the super class of all java class?

The Object class is the superclass of all other


classes in Java and a part of the built-in
java. lang package. If a parent class isn't
specified using the extends keyword, the class
will inherit from the Object class

14. What is use of scanner class?

Scanner class is part of the ‘[Link]’ package.


The Scanner is mostly used to receive user
input and parse them into primitive data
types such as int, double or default String.

You might also like