Oops Programs
Oops Programs
1. What is a class?
2. What is an object?
5. OOPs concept?
9. What is inheritence?
1
OOPS PROGRAMS
b)static variables
c)non-static variables
d)Non of the above.
15What is a constructor?
2
OOPS PROGRAMS
d)Both the methods have same/different return type
e)Both methods may have same/different access specifier
options:
a)a,b,d,e
b)c,d,e
c)b and d
d)c and d.
3
OOPS PROGRAMS
21:which of the following statement interface method is used to delete the data?
a)executeUpdate()
b)execute()
c)executeQuery()
d)executedelete()
22:Which two statements are true about has-a and is-a relationship?
(choose two)
4
OOPS PROGRAMS
a)static method will not participate in inheritence
b)We can not overload static method
c)We can override is variable of a super class inside method class
d)We can assign child class object to the parent class object.
5
OOPS PROGRAMS
Arrays.fill(array,"Hello");
System.out.println(array[i]);
}
}
a)e
b)null
c)Hello
d)ArrayindexOutOfBoundsException.
a)false,false
b)false,true
c)true,false
d)true,true
6
OOPS PROGRAMS
29.What is a constructor?
33.What ia an identifier?
34.What is class?
35.What is object?
38.What is an interface?.Expalin?
7
OOPS PROGRAMS
39.What is public static void main(String[] args ) in java?
48.What is a constructor?
8
OOPS PROGRAMS
51.What is encapsulation?
52.What is inheritence?
58.Explain inheritence?
61.What is pre-order,post-order,in-order?
62.Post-order?with example?
9
OOPS PROGRAMS
63.What is prefix,suffix with examples?
65.What is constructor?
70.What is constructor
71.What is java
10
OOPS PROGRAMS
73.What is object
74.What is class
75.What is abstract
76.What is inheritance
77.What is polymorphism
80.Method overloading
81.Method overriding
83.Method binding
84.Abstraction
11
OOPS PROGRAMS
85.interface
12
OOPS PROGRAMS
}
13
OOPS PROGRAMS
91.The mechanism that binds code and data together and keeps them secure from
outside world is known as
a)Abstraction
b)Encapsulation
c)Inheritence
d)Polymorphism
14
OOPS PROGRAMS
return 0;
}
a)5 2 5
b)5 2 2
c)5 1 4
d)5 3 2
94.Abstraction
95.Interface
96.Inherotence
97.Encapsulation
98.Polymorphism.
99.What is a constructor.
15
OOPS PROGRAMS
b)static methods must only access static data.
c)static methods cannot refer to this or super in any way.
d)When object of class is declared,each object contains its own copy of static methods.
101.class Temp
{
private static int x=10;
private static int y=10;
private Temp()
{
this(9);
}
private Temp(int x)
{
this(x,y);
}
private Temp(int x,int y)
{
System.out.println(x*y);
}
public final static void main(String[] args)
{
Temp t = new Temp();
}
16
OOPS PROGRAMS
}
102.class HackerEarth
{
static void proc1()
{
System.out.println("Inside proc1");
throw new IllegalAccessException("java");
}
public static void main(String[] args)
{
proc1();
}
}
103.Which of the following ways to create an object of the sample class given below
and will work correctly?
class Sample
{
int i;
single j;
double k;
public sample(int ii,single jj,double kk)
17
OOPS PROGRAMS
{
i=ii;
j=jj;
k=kk;
}
}
18
OOPS PROGRAMS
111.What is constructor.
112.What is inheritence.
117.Program on upcasting.
120.What is encapsulation.
19
OOPS PROGRAMS
125.Oops concepts
126.Constructor variables
127.What in heritence
132.Interface in java.
133.Uses of interface.
20
OOPS PROGRAMS
135.What is oops
137.What is polymorphism.
138.What is a constructor.
141.What is a class
144.OOPs concept.
21
OOPS PROGRAMS
147.class Parent{
static void test(){
System.out.println("Parent");
}
}
22
OOPS PROGRAMS
System.out.println("Child");
}
public static void main(String[] args){
Parent p= new Child();
p.test();
}
}
148.final classA
{
System.out.println("Hello World");
}
class B extends A
{
System.out.println("Have a great day");
}
class demo{
public static void main(String[] args)
{
B obj = new B();
}
}
23
OOPS PROGRAMS
static Boolean b1[] = new Boolean(5);
public static void main(String args[]){
System.out.println(b[0]);
}
}
152.What is inheritence.
156.Inheritance
157.Interface
158.Abstract
24
OOPS PROGRAMS
159.OOPs concept
160.Arrays
161.Collection basics.
163.Which of the following loops will execute the body of the loop.
even when the condition is initially false.
25
OOPS PROGRAMS
176.What is oops
26
OOPS PROGRAMS
class Derived
{
public void getDetails (String temp)
{
System.out.println("Derived class" +temp);
27
OOPS PROGRAMS
}
public class Test extends Derived
{
public int getDetails (String temp)
{
System.out.println("Test class" +temp);
return 0;
}
public static void main(String[] args)
{
Test obj - new Test ();
obj.getDetails ("GFG");
}
}
}
Options
A.Runtime error
B.Denved class GFG
C.Test class GFG
D.Compilation error
E.Derved class GFG Test class GFG
28
OOPS PROGRAMS
{
public void getDetails()
{
System.out.printf("Derived class ");
}
}
public class Test extends Derived
{
public void getDetails()
{
System.out.printf("Test class ");
super.getDetails();
}
public static void main(String[] args)
{
Derived ob new Test();
obj.getDetails();
}
}
Options
A.Test class Derived class
B.Derived class Test class
C.Test class
D.Compilation error
29
OOPS PROGRAMS
E.Runtime effor
30
OOPS PROGRAMS
}
Options
A.Compilation error
B.20
C.Constructor called
D.Method called
E.Constructor called Method called
class Helper
{
private int data;
private Helper()
{
data = 5;
}
}
public class Test
{
public static void main(String[] args)
{
Helper help - new Helper();
System.out.println(help.data);
31
OOPS PROGRAMS
}
Options
A.Compilation error-the constructor Helper()'not accessible
B.5
C.Compilation error- the private variable can not be assigned
D.Compilation error - the variable 'data' not accessible
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun()
{
return 20;
}
}
Options
A.20
B.Compile-time error
C.Run-time error
D.Some Garbage value will be printed
32
OOPS PROGRAMS
33
OOPS PROGRAMS
200.What is the number of parameters that a default constructor requires?
a)1
b)0
c)2
d)3
202.Under which pillar of OOPS do base class and derived class relationships come?
A)Polymorphism
B)Encapsulation
C)Inheritance
D)Abstraction
34
OOPS PROGRAMS
204.Which among the following doesn't come under OOP concept?
a)Data hiding
b)Message Passing
c)Platform independent
d)Data binding
208.Ooops concepts
209.polymorphism definition
210.Encapsulation definition
211.Inheritance definition
35
OOPS PROGRAMS
212.Local and global variable
213.Constructor
214.OOPs concept
215.Pillar of OOPs
216.Polymorphism
217.OOPs concept
219.Polymorphism
220.Encapsulation
222.Polymorphism
223.Encapsulation
36
OOPS PROGRAMS
224.Abstraction
225.Inheritence
228.Java language has support for which of the following types of comment.
a)block,Line and javadoc.
b)javadoc,char and String.
c)single,multiple and quote.
d)javadoc,literal and string.
229.------------ is a mechanism for naming and visibility control of a class and its content.
a)None of the mentioned
b)Object
c)Packages
d)Interfaces
37
OOPS PROGRAMS
d)translates java source code to byte code.
231.Polymorphism
232.Encapsulation
236.What is inheritence?
a)interface
b)String
c)float
d)unsigned
38
OOPS PROGRAMS
final void dispaly()
{
System.out.println("Hello");
}
}
class Y extends X
{
void display()
{
System.out.print("Welcome");
}
}
a)class extends
b)display
c)void display
d)System.out.println
a)b2 object
b)new object
39
OOPS PROGRAMS
c)b1 object
d)same object
1.Difference between constructor overloading and method overloading.
241.Multi-level inheritence.
243.Encapsulation
40