Professional Documents
Culture Documents
Practice Worksheet 5
Practice Worksheet 5
1. The _______ operator is used to instantiate a class by allocating memory to its object.
a. dot
b. new
c. this
2. __________ is a special function which gets executed automatically every time an instance of the class is created.
a. object
b. compiler
c. constructor
6._____________ are common to all objects and are shared by all objects
a. instance variables
b. class variables
c. global variables
3. A member declared as private can be accessed only inside the class and by the subclasses in the same package.
a. true
b. false
4. Local variables are declared inside a class and are available to all the functions in the class.
a. true
b. false
7. Every class has a constructor. Explicitly defined by the user or implicitly created by the compiler.
a. true
b. false
class Test
{
private int marks;
int grade;
protected rollno;
d.Name the variables which can be accessed by the class which inherits the above class
1.marks,grade
2.grade,rollno
3.marks,rollno
f.Name the member which can be accessed in the class, same package and also any other package
1.marks
2.rollno
3.grade
Q4. Consider the class given below and answer the questions given below –
class Demo
{
int a;
static int b;
a.How many bytes will 1 instance of the class reserve in the memory?
1. 4
2. 8
3. 6
d.Write a statement which shows a call to the function hello() without any instance.
1. Demo d1=new Demo() ; d.hello();
2. Demo.hello();
3. Demo();
2. Write the memory in bytes that the 3 instances of the below class will occupy
class ShowRoom
{
//datamembers
String branchName;
int branchId;
static ownerName;
}
3. class Myclass
import java.util.*;
class Student
{
String nm;
int m1,m2,m3,max;
double avg;
//Application
class studentapp
{
public ______11__ __12______ main()
{
_________13_________ ;
s1.input();
s1.calc();
s1.display();
}
}