In order to restrict a variable of a class from inheriting to a subclass, how variable should be declared?

Wipro-inheritance

Quiz
•
Computers
•
University
•
Hard
Karthika IT
Used 1+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Private
Protected
Public
Both private and public
2.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A class member declared protected becomes member of subclass of which type?
protected member
private member
static member
public member
3.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What will be the output of the following?
class A
{
public int i;
private int j;
}
class B extends A
{
void display()
{
super.j=super.i+1;
System.out.println(super.i+" "+super.j);
}
}
class inheritance
{
Public static void main(String args[])
{
B obj=newB();
obj.i=1;
obj.j=2;
obj.display();
}
}
2 2
3 3
Runtime error
Compilation error
4.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Determine the output
Class A{
public void printName(){
System.out.println("Name-A");
}
}
class B extendsA{
public oid printName(){
System.out.println("Name-B");
}
}
class C extendsA{
public void printName(){
System.out.println("Name-C");
}
}
public class Test{
public static void main (String[] args){
B b=new B();
C c=new C();
b = c;
newPrint(b);
}
public static void newPrint(A a){
a.printName();
}
}
Name-B
Compilation error
Run time error
Name-A
5.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Inheritance relationship in Java language is
Association
Is-A
Has-A
None
6.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What is the output of this program?
class A
{
public int i;
protected int j;
}
class B extends A
{
int j;
void display()
{
super.j=3;
System.out.println(i+" "+ j);
}
}
class Output
{
public static void main(String args[])
{
B obj=new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
1 2
2 1
1 3
3 1
7.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What is the result of compiling and running the following code?
class Base{
public Base(){
System.out.print("Base");
}
}
public class Derived extends Base{
public Derived(){
this("Exam veda");
System.out.print("Derived");
}
public Derived(String s){
System.out.print(s);
}
public static void main(String[] args){
new Derived();
}
}
Exam veda Derived
Exam veda Base Derived
Base Exam veda Derived
Exam veda Derived Base
Create a free account and access millions of resources
Similar Resources on Quizizz
10 questions
Core Java Quiz

Quiz
•
University
10 questions
CMP128 Java Ch. 05 Methods

Quiz
•
University
7 questions
Quiz on Java Operators

Quiz
•
University
15 questions
II CSM A & B

Quiz
•
University
12 questions
javaquizvivek

Quiz
•
University
10 questions
Java Control Flow statements

Quiz
•
University
10 questions
Java Arrays

Quiz
•
University
10 questions
Java quiz based on inheritance

Quiz
•
University
Popular Resources on Quizizz
15 questions
Character Analysis

Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
10 questions
American Flag

Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25

Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade