Q1 considerthe following statements: public class YClass { private int a; privat
ID: 3611821 • Letter: Q
Question
Q1 considerthe following statements:public class YClass
{
private int a;
private int b;
public void one()
{
}
public void two(int x,int y)
{
}
public YClass()
{
}
}
public XClass extends YClass
{
private int z;
public void one()
{
}
public XClass()
{
}
}
YClass yObject;
XClass xObject;
a.is this definition valid of the method one of YClass?
public void one()
{
System.out.println(a+b);
}
a.is this definition valid of the method one of XClass?
public void one()
{
a=10;
b=15;
z=30;
System.out.println(a+b+z);
}
Q2
Suppose that you have the following class:
public class classA
{
private int x;
protected void setX(int a)
{
x=a;
}
}
What is the wrong with the following code?
public class Exercise10
{
public static void main(String[]args)
{
classA aObject;
aObject.setX(4);
}
} Q1 considerthe following statements:
public class YClass
{
private int a;
private int b;
public void one()
{
}
public void two(int x,int y)
{
}
public YClass()
{
}
}
public XClass extends YClass
{
private int z;
public void one()
{
}
public XClass()
{
}
}
YClass yObject;
XClass xObject;
a.is this definition valid of the method one of YClass?
public void one()
{
System.out.println(a+b);
}
a.is this definition valid of the method one of XClass?
public void one()
{
a=10;
b=15;
z=30;
System.out.println(a+b+z);
}
Q2
Suppose that you have the following class:
public class classA
{
private int x;
protected void setX(int a)
{
x=a;
}
}
What is the wrong with the following code?
public class Exercise10
{
public static void main(String[]args)
{
classA aObject;
aObject.setX(4);
}
}
Explanation / Answer
a)Given program observedthen takepublic XClass extends YClass.
In the above line 'class' keywardis missing.So given definition not valid of the method one ofYClass
a)In main method no objectcreated.So ,given definition not valid of the method one ofXClass. ITS HELPFUL TO YOU...... ITS HELPFUL TO YOU......
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.