Professional Documents
Culture Documents
11. Write a Java Program to read different data type values form user by using
Scanner class and print the same.
12. Write a simple java program to add two nmbers.
Long Questions:
1. List and explain the Scanner class methods used for reading different types of data.
2. Analyze the characteristics of final methods and final classes with suitable examples.
3. Compare and Contrast entry controlled and exit controlled loops with a suitable
example for each.
4. Analyze the characteristics of static methods with suitable examples.
5. List and explain the different integer types of Java along with the number of bytes they
occupy and their range.
6. Demonstrate the concept of method overriding with an example.
7. Analyze the process of achieving Call by Reference in java with an example.
8. Discuss about the various Access specifiers and their significance with an example.
9. Analyze the process of achieving Call by Reference in java with an example.
10. Bring out the uses of final keyword.
11. Develop a program in Java to print the program as output
12. write the difference between overloading and overriding.
13. Develop a java program to define a class called Student with 2 fields (Name, Id) and two
constructors one a default constructor and the other, a parameterized constructor to initialize
the fields. Incorporate a show() method to display the field values. Create objects for the class
and analyze the steps of the program.
14. Bring out the significance of labelled break and labelled continue with a suitable
example for each.
15. Analyze the application of this keyword to resolve naming conflicts.
1. Define a class Area with two derived classes Square and Rectangle each with a method
with same name findArea() that compute and return the area of rectangle, and square
respectively. Incorporate a main method to invoke and to retrieve the results of these
methods.
2. Develop a program to perform Bitwise Shift operations (<<, >> and >>>) on suitable
data. Employ the Integer.toBitString() method to display the results.
3. Bring out the memory allocation procedure for non-static and static members of a class
along with the difference in procedure to invoke non-static and static methods.
Appreciate the characteristics of static fields and static methods with suitable examples.
4. Develop a java program to find the sum and average of n elements. Use a 1D array to
implement the same
5. Discuss the concept of Method overloading? Analyze with an example
Develop a java program to search for an element in an array of n elements.
6. Implement the Linear Search Technique
Solutions
A: OOP concepts in Java are the main ideas behind Java’s Object Oriented
Programming. They are an abstraction, encapsulation, inheritance,
and polymorphism. Grasping them is key to understanding how Java works.
Basically, Java OOP concepts let us create working methods and variables, then
re-use all or part of them without compromising security.
PROGRAMMING PROGRAMMING
PROGRAMMING PROGRAMMING
Adding new data and function is Adding new data and function is
have any proper way for hiding provides data hiding so it is more
data. function.
PROGRAMMING PROGRAMMING
Basic The length of the String object The length of the StringBuffer can
is fixed. increased.
concatenation.
STATIC VARIABLE
class VariableDemo
{
static int count=0;
public void increment()
{
count++;
}
public static void main(String args[])
{
VariableDemo obj1=new VariableDemo();
VariableDemo obj2=new VariableDemo();
obj1.increment();
obj2.increment();
System.out.println("Obj1: count is="+obj1.count);
System.out.println("Obj2: count is="+obj2.count);
}
}
Output:
EXAMPLE-
int x;
public MyClass(int x) {
this.x = x;
Inheritance is the process of creating a new Class, called the Derived Class, from
the existing class, called the Base Class. The Inheritance has many advantages,
the most important of them being the reusability of code. Rather than
developing new Objects from scratch, new code can be based on the work of
other developers, adding only the new features that are needed. The reuse of
existing classes saves time and effort.
Single Inheritance
Multi Level Inheritance
Hierarchical Inheritance
Hybrid Inheritance
Multipath inheritance
Multiple Inheritance
Single Inheritance
When a Derived Class to inherit properties and behavior from a single Base Class,
it is called as single inheritance.
Hierarchical Inheritance
More than one derived class are created from a single base class, is called
Hierarchical Inheritance
Hybrid Inheritance
Any combination of above three inheritance (single, hierarchical and multi level)
is called as hybrid inheritance.
Multipath inheritance
Multiple Inheritance
Multiple inheritances allows programmers to create classes that combine
aspects of multiple classes and their corresponding hierarchies. In .Net
Framework, the classes are only allowed to inherit from a single parent class,
which is called single inheritance. More about.... Why in .NET multiple
inheritance is not allowed
class Animal {
1. Define a class Area with two derived classes Square and Rectangle each with a
method with same name findArea() that compute and return the area of rectangle, and
square respectively. Incorporate a main method to invoke and to retrieve the results
of these methods.
answer
refer material
2.Develop a program to perform Bitwise Shift operations (<<, >> and >>>) on suitable data.
Employ the Integer.toBitString() method to display the results.
int a = 5;
int b = -10;
Output :
a<<2 = 20
b>>2 = -3
b>>>2 = 1073741821
3. Bring out the memory allocation procedure for non-static and static members of a class
along with the difference in procedure to invoke non-static and static methods. Appreciate the
characteristics of static fields and static methods with suitable examples.
Link:-
https://www.geeksforgeeks.org/difference-between-static-and-non-static-method-in-java/
4. Develop a java program to find the sum and average of n elements. Use a 1D array to
implement the same
return sum / n;
}
//driver code
public static void main (String[] args)
{
System.out.println(average(arr, n));
}
}
Output:
6
filter_none
edit
play_arrow
brightness_4
// Java program to demonstrate working of method
// overloading in Java.
return (x + y);
}
// Overloaded sum(). This sum takes three int parameters
return (x + y + z);
return (x + y);
// Driver code
System.out.println(s.sum(10, 20));
System.out.println(s.sum(10.5, 20.5));
}
Output :
30
60
31.0
int x = 4;
2) final method
A final method cannot be overridden. Which means even though a sub class can
call the final method of parent class without any issues but it cannot override it.
Example:
class XYZ{
final void demo(){
System.out.println("XYZ Class Method");
}
}
class XYZ{
final void demo(){
System.out.println("XYZ Class Method");
}
}
3) final class
We cannot extend a final class. Consider the below example:
3. Compare and Contrast entry controlled and exit controlled loops with a suitable example
for each.
Answer Link:-
https://www.includehelp.com/c-programming-questions/difference-between-
entry-and-exit-controlled-loop.aspx
Answer Link:-
https://www.geeksforgeeks.org/overriding-in-java/
https://www.geeksforgeeks.org/difference-between-call-by-value-and-call-by-
reference/
8.Discuss about the various Access specifiers and their significance with an example.
filter_none
edit
play_arrow
brightness_4
//filename: Main.java
14. Bring out the significance of labelled break and labelled continue with a suitable example
for each.
Links :-
Break
https://www.tutorialspoint.com/java/java_break_statement.htm
continue
https://www.tutorialspoint.com/java/java_continue_statement.htm