0% found this document useful (0 votes)
47 views

Suggessio GRD

The document contains questions about object-oriented programming concepts like encapsulation, inheritance, polymorphism, abstraction, and packages. It also contains code snippets and questions to predict the output. Some key concepts covered are method overloading vs overriding, static methods and variables, inheritance, polymorphism, abstract classes vs interfaces, and use of keywords like final, this and super.

Uploaded by

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

Suggessio GRD

The document contains questions about object-oriented programming concepts like encapsulation, inheritance, polymorphism, abstraction, and packages. It also contains code snippets and questions to predict the output. Some key concepts covered are method overloading vs overriding, static methods and variables, inheritance, polymorphism, abstract classes vs interfaces, and use of keywords like final, this and super.

Uploaded by

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

OBJECT ORIENTED PROGRAMMING (PCCCS503)

Question-5 marks

• What is encapsulation?How does a class accomplish data hiding? Give example. List out the differences between
Procedural and Object oriented programming.
• Write a program to access static variable and static method to explain static keyword property.

• What are the benefits of organizing classes into package?How can you create your own package and add classes to
that? Explain with help of an example

• What are the differences between method overloading and method overriding? What is dynamic binding and early
binding.Explain dynamic method dispatch with a suitable example.
• What is interface?Explain with help of an example how java gets befitted by using interface. Illustrate abstract class
with an example. Differentiate abstract class with interface.
• Describe a mechanism where both Inheritance and Polymorphism is used. Explain with an example.
• Explain the use of final keyword using a example program.

Question 1 marks

1. Which of this keyword must be used to inherit a class?


2. Which of the following is true about inheritance in Java?

• Private methods are final.


• Protected members are accessible within a package and
• inherited classes outside the package.
• Protected methods are final.
• We cannot override private methods.
3. Identify the correct restriction on static methods.
• They must access only static data
• They can only call other static methods.
• They cannot refer to this or super.
4. Super refers to ---------------
5. -----------------keyword is used to declare class constant.
6. Method overloading shows ………………………….polymorphism.
Predict output of following

1.Public class Test{


Public static void main(String argos[]){
String str1 = “one”;
String str2 = “two”;
System.out.println(str1.concat(str2));
}
}

2. class A
{
int i;
void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
class inheritance_demo
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}

3. class average {
public static void main(String args[])
{
double num[] = {5.5, 10.1, 11, 12.8, 5.5};
double result;
result = 0;
for (int i = 0; i < 6; ++i)
result = result + num[i];
System.out.print(result/6);

}
}

4. class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * ++g);
}
}

5. class selection_statements
{
public static void main(String args[])
{
int var1 = 4;
int var2 = 6;
if ((var2 = 1) == var1)
System.out.print(var2);
else
System.out.print(++var2);
}
}
6. class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + " " + obj.j) }}

7. public class Calculator


{
int num = 100;
public void calc(int num) { num = num * 10; }
public void printNum() { System.out.println(num); }

public static void main(String[] args)


{
Calculator obj = new Calculator();
obj.calc(2);
obj.printNum();
}
}

8. class main_class
{
public static void main(String args[])
{
int x = 9;
if (x == 9)
{
int x = 15;
System.out.println(x);
}}

9. class box
{
int width;
int height;
int length;
}
class mainclass
{
public static void main(String args[])
{
box obj = new box();
obj.width = 10;
obj.height = 20;
obj.length = 10;
int y = obj.width * obj.height * obj.length;
System.out.print(y);
}
}

10. class Base {


public void show() {
System.out.println("Base::show() called");
}
}

class Derived extends Base {


public void show() {
System.out.println("Derived::show() called");
}
}

public class Main {


public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}

11. public class Test


{
static
{ System.out.print("1"); }

static
{System.out.print("2"); }

static
{ System.out.print("3"); }

private int function()


{return 4; }

private static int myMethod()


{ return 5; }

public static void main(String[] args)


{
System.out.println((new Test()).function()+myMethod());
}
}

You might also like