Java Viva Question and Answer: Q) What Is Object Oriented Language ?
Java Viva Question and Answer: Q) What Is Object Oriented Language ?
Disadvantages
● The program code is harder to write when Procedural Programming is
employed
● The Procedural code is often not reusable, which may pose the need to
● The importance is given to the operation rather than the data, which might
● The data is exposed to the whole program, making it not so much security
friendly
Q) Comparison between procedural language and Object-Oriented Language
Adding new data and function is not easy. Adding new data and function is easy.
Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C# etc.
1) What is OOPS?
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
3) What is a class?
An object is an instance of a class. It has its own state, behavior, and identity.
Q) What is an abstraction?
5) What is Encapsulation?
6) What is Polymorphism?
7) What is Inheritance?
Inheritance is a concept where one class shares the structure and behavior
defined in another class. If Inheritance applied to one class is called Single
Inheritance, and if it depends on multiple classes, then it is called multiple
Inheritance.
Advantages of OOP
Q) What is Java
Features of Java
● 1) Simple. Java is easy to learn and its syntax is quite simple, clean and
easy to understand. ...
● 2) Object Oriented. In java, everything is an object which has some data
and behaviour. ...
● 3) Robust. ...
● 4) Platform Independent. ...
● 5) Secure. ...
● 6) Multi Threading. ...
● 7) Architectural Neutral. ...
● 8) Portable.
Q) What is java virtual machine
It is non-executable code
A Java™ runtime environment (JRE) is a set of components to create and run a Java
application. A JRE is part of a Java development kit (JDK).
A JRE is made up of a Java virtual machine (JVM), Java class libraries, and the Java class
loader. JDKs are used to develop Java software; JREs provide programming tools and
deployment technologies; and JVMs execute Java programs.
Q) Java APIS
Contains hundred of classes and methods grouped into several functional package
Language support package
Utility package
Input output package
Networking package
AWT package
Applet package
Variable defined inside the methods constructors or blocks are called local variable
The variable will be declared and intilalized within the method and the variable will be destroyed
when the method has completed
Class level scope (instance variables): any variable declared within a class is
accessible by all methods in that class. Depending on its access modifier (ie.
public or private), it can sometimes be accessed outside the class.
Method level scope (local variables): any variable declared within a method,
arguments included, is NOT accessible outside that method.
Block scope (loop variables): any variable declared in a for loop condition is not
accessible after the loop, unless you defined it beforehand.
In Java, there are four access modifiers that restrict the accessibility of the
method or variable to which the modifier is applied. They are only used within
classes, not within methods. public and private are the most relevant modifiers
to our work, but we will briefly discuss all of them.
Q) STATIC IN JAVA
Q)
Method overriding is a topic that comes up a few times in this path. It is a feature in Java that
allows a subclass to have a method with the same name and parameters as one declared in its
parent class. This is handy because it allows a subclass to implement a specific behavior for
that method. The version of the method used is determined by the object that is used to call it.
For more detailed information regarding classes and subclasses, check out our lesson on
Inheritance and Polymorphism in Java. An implementation of method overriding can be found in
exercise six of this lesson.
Method overloading is similar to overriding in that it involves methods with the same name.
However with overloading, a single Java class can have multiple methods with the same name if
they have different parameter lists. Overloaded methods are distinguished by their number and
type of parameters.
Define Destructor?
A destructor is a method which is automatically called when the object is made
of scope or destroyed. Destructor name is also same as class name but with the
tilde symbol before the name.
Constructors Methods
Q) Recursion
Is a technique by which a function calls itself
Q) What is an array
● Arrays represent multiple data elements of the same type using a single name.
● In an array, accessing or searching an element is easy by using the index number.
● An array can be traversed easily just by incrementing the index by 1.
● Arrays allocate memory in contiguous memory locations for all its data elements.
2D Array
2 Dimensional array are often defined as an array of arrays. A 2D array is also called a
STRING
characters. In the Java programming language, strings are objects. The Java
STRING BUFFER :-
STRING BUFFER CLASS METHOD :-
EXCEPTIONAL :-
TRY CATCH BLOCK
FINALLY :-
THROW KEYWORD :-
THROWS KEYWORD:-
MULTI THREADING
JOIN METHOD
THREAD PRIORITIES
SYNCHONIZATION
SYNCHRONIZED BLOCK:-
Example
Finalize method helps to perform cleanup operations on the resources which are
not currently used. Finalize method is protected, and it is accessible only through
this class or by a derived class.
● Call by Value – Value passed will get modified only inside the function, and
it returns the same value whatever it is passed into the function.
● Call by Reference – Value passed will get modified in both inside and
outside the functions and it returns the same or different value.
The super keyword is used to invoke the overridden method, which overrides one
of its superclass methods. This keyword allows to access overridden methods
and also to access hidden members of the superclass.
Overriding is the same method names with the same arguments and return types
associated with the class and its child class.
Abstraction is a useful feature of OOPS, and it shows only the necessary details
to the client of an object. Meaning, it shows only required details for an object,
not the inner constructors, of an object. Example – When you want to switch on
the television, it is not necessary to know the inner circuitry/mechanism needed
to switch on the TV. Whatever is required to switch on TV will be shown by using
an abstract class.
Access modifiers determine the scope of the method or variables that can be
accessed from other various objects or classes. There are five types of access
modifiers, and they are as follows:
● Private
● Protected
● Public
● Friend
● Protected Friend
Sealed modifiers are the access modifiers where the methods can not inherit it.
Sealed modifiers can also be applied to properties, events, and methods. This
modifier cannot be used to static members.
30) How can we call the base method without creating an instance?
Yes, it is possible to call the base method without creating an instance. And that
method should be “Static method.”
Doing Inheritance from that class.-Use Base Keyword from a derived class.
The new modifier instructs the compiler to use the new implementation instead
of the base class function. Whereas, Override modifier helps to override the base
class function.
Early binding refers to the assignment of values to variables during design time,
whereas late Binding refers to the assignment of values to variables during run
time.
THIS pointer refers to the current object of a class. THIS keyword is used as a
pointer which differentiates between the current object with the global object. It
refers to the current object.
The default access type of a Structure is public, but class access type is private.
A structure is used for grouping data, whereas a class can be used for grouping
data and methods. Structures are exclusively used for data, and it doesn’t require
strict validation, but classes are used to encapsulate and inherent data, which
requires strict validation.
The default access modifier of a class is Internal and the default access modifier
of a class member is Private.
A pure virtual function is a function which can be overridden in the derived class
but cannot be defined. A virtual function can be declared as Pure by using the
operator =0.
Example –
42) What does the keyword virtual represented in the method definition?
False.
The base class is the most generalized class, and it is said to be a root class.
Binding is nothing but the association of a name with the class. Static Binding is
a binding in which name can be associated with the class during compilation
time, and it is also called as early Binding.
Dynamic Binding is a binding in which name can be associated with the class
during execution time, and it is also called as Late Binding.
Zero instances will be created for an abstract class. In other words, you cannot
create an instance of an Abstract Class.
50) Which OOPS concept exposes only the necessary information to the calling
functions?
Encapsulation